hana - Using SQL to get the continuous range of table -
here table named track , have 3 columns: time
, speed
, isoverspeed
, below
time speed isoverspeed 10:00:01 76 1 10:00:11 58 0 10:00:21 70 1 10:00:31 70 1 10:00:41 90 1 10:00:51 40 0 10:01:01 30 0 10:01:11 80 1 10:01:21 20 0
what want calculate how many times , how long car overspeed
, requirement continuous overspeed
records count 1 time, in example, there 3 times overspeed
not 4. thinking using window function seems not work. has idea? ps. result should 3 times, 50 seconds.
i think need this:
select count(*) cnt, sum(seconds_between(dt.prevtime, dt.time)) sometime ( select t1.time, max(t2.time) prevtime atable t1 join atable t2 on t1.time > t2.time t1.isoverspeed = 1 group t1.time) dt
Comments
Post a Comment