sql - Find time period in list of status changes (per status) -


i have list of moments specific user on specific workstation:

    station timestamp     tc61879 2016-03-25 09:34:40.000     tc61879 2016-03-25 09:38:36.000     tc61879 2016-03-25 10:01:17.000     tc61879 2016-03-25 10:02:10.000     tc61879 2016-03-25 10:04:01.000     tc61879 2016-03-25 10:04:43.000     tc61879 2016-03-25 10:05:49.000     tc61879 2016-03-25 10:06:00.000     tc61878 2016-03-25 10:08:05.000*     tc61879 2016-03-25 10:09:41.000     tc61879 2016-03-25 10:10:40.000     tc61879 2016-03-25 10:35:50.000     tc61879 2016-03-25 10:37:57.000     tc61879 2016-03-25 10:38:21.000     tc61879 2016-03-25 10:39:34.000     tc61879 2016-03-25 10:40:59.000     tc61879 2016-03-25 10:41:20.000     tc61879 2016-03-25 10:42:21.000     tc61879 2016-03-25 10:44:05.000     tc61879 2016-03-25 10:44:17.000     tc61879 2016-03-25 10:46:25.000     tc61879 2016-03-25 10:47:48.000     tc61879 2016-03-25 10:49:03.000     tc61879 2016-03-25 10:51:31.000     tc61879 2016-03-25 10:51:58.000     tc61875 2016-03-25 10:52:42.000*     tc61875 2016-03-25 10:53:49.000*     tc61879 2016-03-25 10:53:57.000     tc61879 2016-03-25 11:36:58.000     tc61879 2016-03-25 11:37:37.000     tc61879 2016-03-25 11:38:45.000     tc61879 2016-03-25 11:40:08.000     tc61879 2016-03-25 11:41:46.000     tc61879 2016-03-25 11:43:43.000     tc61879 2016-03-25 11:44:49.000     tc61879 2016-03-25 11:46:06.000     tc61879 2016-03-25 11:48:17.000     tc61879 2016-03-25 11:50:22.000     tc61879 2016-03-25 11:52:06.000     tc61879 2016-03-25 11:52:22.000     tc61879 2016-03-25 11:53:07.000     tc61879 2016-03-25 11:55:29.000     tc61879 2016-03-25 11:55:49.000     tc61879 2016-03-25 11:56:24.000     tc61879 2016-03-25 11:57:20.000     tc61879 2016-03-25 11:57:55.000     tc61879 2016-03-25 11:58:15.000     tc61879 2016-03-25 11:59:05.000     tc61879 2016-03-25 11:59:17.000     tc61878 2016-03-25 11:59:52.000*     tc61879 2016-03-25 12:00:08.000     tc61879 2016-03-25 12:01:04.000     tc61879 2016-03-25 12:01:36.000     tc61878 2016-03-25 12:04:42.000*     tc61879 2016-03-25 12:04:46.000     tc61879 2016-03-25 12:05:37.000     tc61878 2016-03-25 12:07:37.000*     tc61879 2016-03-25 12:07:47.000     tc61879 2016-03-25 12:08:36.000     tc61879 2016-03-25 12:10:16.000     tc61879 2016-03-25 12:11:30.000 

asterisk when user did on different workstation default one. need list of from-to per workstation, this:

station                            tc61879      2016-03-25 09:34:40.000    2016-03-25 10:08:05.000 tc61878      2016-03-25 10:08:05.000    2016-03-25 10:09:41.000 tc61879      2016-03-25 10:09:41.000    2016-03-25 10:52:42.000 tc61875      2016-03-25 10:52:42.000    2016-03-25 10:53:57.000 tc61879      2016-03-25 10:53:57.000    2016-03-25 11:59:52.000 tc61878      2016-03-25 11:59:52.000    2016-03-25 12:00:08.000 tc61879      2016-03-25 12:00:08.000    2016-03-25 12:04:42.000 tc61878      2016-03-25 12:04:42.000    2016-03-25 12:04:46.000 tc61879      2016-03-25 12:04:46.000    2016-03-25 12:07:37.000 tc61878      2016-03-25 12:07:37.000    2016-03-25 12:07:47.000 tc61879      2016-03-25 12:07:47.000    2016-03-25 12:11:30.000 

i have tried various things window functions , joins, keep having problem that, when users switches 1 workstation , data not reflect when user did on other workstation.

select station resulttable @datetime between , 

this query should give 1 row result

eventually want use data determine user in given datetime.

how should approach this?

you want assign groups based on changes in column (ordered time). there "trick" using difference of row numbers makes quite easy:

select station, min(timestamp), max(timestamp) (select t.*,              row_number() on (order timestamp) seqnum_t,              row_number() on (partition station order timestamp) seqnum_wst       t      ) t group (seqnum_t - seqnum_wst), station; 

if @ sequential numbers generated, first enumerating rows. second enumerates rows within each station. when rows sequential, difference constant.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -