Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT IFNULL(t.max, 0) as max
- FROM (
- SELECT @start := UNIX_TIMESTAMP('2019-01-23 10:30:00 AM'),
- @end := UNIX_TIMESTAMP('2019-01-23 12:00:00 PM'),
- max(x.total) as max
- FROM (
- SELECT @total := 0 as total
- UNION
- SELECT @total := @total + qty as total
- FROM (
- SELECT start_time as time, qty
- FROM temp_events
- WHERE end_time >= UNIX_TIMESTAMP('2019-01-23 10:30:00 AM')
- AND start_time <= UNIX_TIMESTAMP('2019-01-23 12:00:00 PM')
- UNION ALL
- SELECT end_time as time, -qty as qty
- FROM temp_events
- WHERE end_time >= UNIX_TIMESTAMP('2019-01-23 10:30:00 AM')
- AND start_time <= UNIX_TIMESTAMP('2019-01-23 12:00:00 PM')
- ORDER BY time ASC, qty ASC
- ) as y) x) t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement