Advertisement
Guest User

Untitled

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