2015-10-01 113 views
0

我正在處理一個數據集,其中我必須比較一天的收入與上週的同一天。在日期比較SQL

樣品我已經共享的數據:

Date DAY_IN_WEEK_NAME onnetMins 
9/18/2015 FRIDAY 311,980,365.00 
9/25/2015 FRIDAY 361,232,362.00 
9/21/2015 MONDAY 299,167,025.50 
9/28/2015 MONDAY 292,725,603.00 
9/19/2015 SATURDAY 310,260,553.00 
9/26/2015 SATURDAY 314,627,373.50 

對於SQL寫入我試圖如下面的查詢:

sel 
(case when day_in_week_name = 'Friday' then 
(distinct (onnetMins)- distinct (onnetMins)) end) 
from MYTABLE group by 1 

然而,它不工作。

任何人都可以嘗試調整這個SQL?

+0

它不工作 - 什麼是您所遇到的問題? – MusicLovingIndianGirl

+0

SQL是不正確的我猜, – user3296651

+0

我需要找到差異onnetMins 9月18日和9月25日通過SQL查詢 – user3296651

回答

1

這是查詢,可以幫助你:

SELECT 
    t1.DAY_IN_WEEK_NAME 
    , t2.onnetMins - t1.onnetMins 
FROM 
    MYTABLE t1 
    INNER JOIN MYTABLE t2 
    ON t1.DAY_IN_WEEK_NAME = t2.DAY_IN_WEEK_NAME 
WHERE 
    t1.date < t2.date 
+0

這有助於。謝謝。 – user3296651