简体   繁体   中英

SQL: Grouping results by the date

I have a table:

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

Is it possible to make a query that results with:

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

Where InTeam Points is a sum of all team points during the day and Not In Team Point is a sum of not in team points during the day?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM