[英]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.