2017-07-18 98 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) 

感謝

也許這也將

有用
相關問題