2017-07-18 96 views
0

我需要从最后一天的数据库scadalts获取数据。如何从最后一天从数据库scadalts获取值

我有表中的数据pointValues哪里是列pointValue和ts但不是时间戳。

ts是键入BIGINT(20)

检查TS是unixtime

 SELECT 
     pointValue, 
     ts, 
     from_unixtime(ts), 
     YEAR(from_unixtime(ts)), 
     MONTH(from_unixtime(ts)), 
     DAY(from_unixtime(ts)) 
    FROM 
     pointValues; 

结果null是错误的不unixtime。

我不知道如何创建条件where,因为 - 我不知道如何解释栏ts中的值。

回答

0

ts应该更准确地解释。

如:

SELECT 
    pointValue, 
    ts, 
    from_unixtime(ts/1000), 
    YEAR(from_unixtime(ts/1000)), 
    MONTH(from_unixtime(ts/1000)), 
    DAY(from_unixtime(ts/1000)) 
FROM 
    pointValues; 

而且我们可以从最后一天,如获取值:

SELECT 
    pointValue, 
    ts, 
    YEAR(from_unixtime(ts/1000)), 
    MONTH(from_unixtime(ts/1000)), 
    DAY(from_unixtime(ts/1000)) 
FROM 
    pointValues 
WHERE 
    YEAR(from_unixtime(ts/1000)) = YEAR(NOW() - INTERVAL 1 day) and 
    MONTH(from_unixtime(ts/1000)) = MONTH(NOW() - INTERVAL 1 day) and 
    DAY(from_unixtime(ts/1000)) = DAY(NOW() - INTERVAL 1 day) 

感谢

也许这也将

有用
相关问题