Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.86 KB | None | 0 0
  1. SELECT IFNULL(t.max, 0) as max
  2. FROM (
  3.        SELECT max(x.total) as max
  4.        FROM (
  5.               SELECT @total := 0 as total,
  6.                      @start := UNIX_TIMESTAMP('2019-01-23 10:30:00 AM'),
  7.                      @end := UNIX_TIMESTAMP('2019-01-23 12:00:00 PM')
  8.               UNION
  9.               SELECT @total := @total + qty as total, null, null
  10.               FROM (
  11.                      SELECT start_time as time, qty
  12.                      FROM temp_events
  13.                      WHERE end_time >= @start
  14.                        AND start_time <= @end
  15.                      UNION ALL
  16.                      SELECT end_time as time, -qty as qty
  17.                      FROM temp_events
  18.                      WHERE end_time >= @start
  19.                        AND start_time <= @end
  20.                      ORDER BY time ASC, qty ASC
  21.                    ) as y) x) t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement