duanbi6522 2015-07-14 05:19
浏览 43
已采纳

以特定间隔将数据从数据库检索到文件中

In database, I have stored data in one second interval, but I want to retrieve the stored data into a file in some particular interval entered by the user.

The data is as below:

TIMESTAMP   VALUES
1436846660  10
1436846661  10
1436846662  10
1436846663  10
1436846664  10

For user entered interval 2, expected result is :

TIMESTAMP   VALUES
1436846660  10
1436846662  10
1436846664  10

I am using the following command to get the data from starttime to stoptime

SELECT
    `VALUES`
INTO
    OUTFILE 'FILEPATH'
    FIELDS TERMINATED BY ''
    LINES TERMINATED BY '
'
FROM
    TABLENAME
WHERE
        TABLENAME.TIMESTAMP >=starttime
    AND TABLENAME.TIMESTAMP <=stoptime;

So, how should I modify this code to include only those data between starttime and stoptime with the particular interval. Please provide me a solution.

  • 写回答

2条回答 默认 最新

  • doucheng1891 2015-07-14 06:06
    关注

    This code worked for me . Interval : 2

    SELECT
        `value`
    --  ,`timestamp`
        INTO outfile 'test.csv'
        FIELDS TERMINATED BY ''
        LINES TERMINATED BY '
    '
    FROM
        `timestamp_table`
    WHERE
            `timestamp` >= 1436846660
        AND `timestamp` <= 1436846670
        AND MOD( `timestamp` ,2) = 0
    

    In the last line , change 2 to whatever interval you would need .

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 Qcustomplot绘制实时动态曲线
  • ¥20 运用matlab画x-y图
  • ¥15 用idea运行项目,运行tomcat报错:断言失败
  • ¥15 Sqlserver查询链接服务器数据问题
  • ¥15 Bibtex4Word 引用中文文献
  • ¥20 用opencv c/c++ 转换成灰度图,然后做一下直方图均衡,输出mp4文件
  • ¥20 matlab中的双层数值积分
  • ¥50 服务器打印水晶报表问题
  • ¥30 gradle环境下javafx项目如何使用druid连接池
  • ¥15 服务器打印水晶报表问题