Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT
  2.   device
  3.   , sum(measurement * num_seconds)
  4.   , max(measurement)
  5.   -- should return 270 as it was the num seconds the measurement was the max of 5
  6.   , last_value(num_seconds) OVER (ORDER BY num_seconds)
  7. FROM (VALUES (1, 4, 6), (1, 4, 270), (1, 5,30), (1, 4, 2640), (1, 3, 654)) t(device, measurement, num_seconds)
  8. GROUP BY 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement