I'm trying to form a SQL statement that meets the following criteria based on records that have date/timestamps and various other varchar and int fields.
- Calculate the difference between two fields named
time_depart
andtime_return
in decimal hours - Total up the differences and group by month up to the last 12 months.
- Separate totals based on
event_type
Example Data Set
table events
:
id | time_depart | time_return | event_type | summary
--------------------------------------------------------------
1 | 2019-02-11 10:00:00 | 2019-02-11 10:30:00 | 1 | test summary
2 | 2019-02-11 10:30:00 | 2019-02-11 11:30:00 | 1 | some more data
3 | 2019-02-11 11:00:00 | 2019-02-11 12:30:00 | 2 | even more data
4 | 2019-02-11 11:30:00 | 2019-02-11 13:30:00 | 2 | just a summary
5 | 2019-02-11 12:00:00 | 2019-02-11 14:30:00 | 2 | again more
......
Would like a return similar to where event_type = 1
is 'training'
and event_type = 2
is a 'mission'
month | trainingTime | missionTime
--------------------------------------------------------------
january | 15.25 | 22
february | 20 | 25
march | 10.5 | 35.5
april | 52 | 20
may | 64 | 72
june | 100 | 10.75
july | 45 | 0
august | 26 | 15
september | 10.5 | 65
october | 55 | 8
november | 44 | 12.25
december | 17 | 0