簡體   English   中英

SQL:按日期分組結果

[英]SQL: Grouping results by the date

我有一張桌子:

EventTime         | InTeam    | Points |
----------------------------------------
2014-07-16 11:40      True       10
2014-07-16 10:00     False       20
2014-07-16 09:20      True       30
2014-07-15 11:20     False        5
2014-07-15 10:20      True       10
2014-07-15 09:00     False       10

是否可以查詢結果如下:

EventDate   | InTeam Points | Not In Team Point |
-------------------------------------------------
2014-07-16                40                  20
2014-07-15                10                  15

InTeam Points是所有車隊積分的白天與和Not In Team Point是不是在車隊積分白天總和?

select date(eventtime) as eventtime,
       sum(case when inteam = 'true' then points end) as in_team_points,
       sum(case when inteam = 'false' then points end) as not_in_team_points
from your_table
group by date(eventtime)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM