Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT *, (temp_max.VALUE - temp_second_max.VALUE) AS FUCKING FROM
- (SELECT test.*
- FROM test
- JOIN (
- SELECT *, MAX(TIME) AS max_time
- FROM test
- GROUP
- BY
- event_type
- ) tmp ON test.event_type = tmp.event_type AND test.TIME = tmp.max_time
- ) temp_max
- JOIN(
- SELECT test.*
- FROM test
- JOIN (
- SELECT t2.event_type, MAX(t2.TIME) AS max_second_time
- FROM test AS t1
- JOIN test AS t2 ON t1.event_type = t2.event_type AND t1.TIME > t2.TIME
- GROUP BY t2.event_type
- ) tmp ON test.event_type = tmp.event_type AND test.TIME = tmp.max_second_time
- ) temp_second_max ON temp_max.event_type = temp_second_max.event_type;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement