I have some data as follows. I’m trying to compute the values in the Time bw
column (it should be 0 in the 4th row). Whenever the Location
moves to a new one, like a
to b
, I want the Time bw
to restart from 0. I’m trying to use ne
,select
and diff()
+----------+---------------------+----------+ | Location | Date | Time bw | +----------+---------------------+----------+ | a | 2018-06-26 00:00:00 | 0 | | a | 2018-06-26 00:00:00 | 0 | | a | 2018-06-26 00:00:00 | 0 | | b | 2018-08-03 00:00:00 | 38 | | b | 2018-08-03 00:00:00 | 0 | | b | 2018-08-04 00:00:00 | 1 | | b | 2018-08-04 00:00:00 | 0 | | b | 2018-08-04 00:00:00 | 0 | | b | 2018-08-04 00:00:00 | 0 | | b | 2018-08-04 00:00:00 | 0 | | b | 2018-08-04 00:00:00 | 0 | | b | 2018-08-05 00:00:00 | 1 | | b | 2018-08-08 00:00:00 | 3 | | b | 2018-08-08 00:00:00 | 0 | | b | 2018-08-08 00:00:00 | 0 | | b | 2018-08-08 00:00:00 | 0 | | b | 2018-08-08 00:00:00 | 0 | | c | 2018-08-14 00:00:00 | 6 | | c | 2018-08-14 00:00:00 | 0 | | c | 2018-08-14 00:00:00 | 0 |
+———-+———————+———-+