Answer the question
In order to leave comments, you need to log in
Getting the time spent in the room by the logs of inputs / outputs?
Good afternoon.
There is a table with a log of employees entering / exiting the premises:
trans_date timestamp
user_id integer
trans_type integer -- 0=вход, 1=выход
Answer the question
In order to leave comments, you need to log in
I suspect that it is necessary to complicate the task: Some employees may check in, but not check in (by mistake to marry someone for the company) and vice versa ... right?
And yes, in any case, you can get by with one request.
The most primitive option:
using window functions, we calculate the delta between adjacent events (for example, in minutes or seconds),
then we aggregate this by employee days, and summarize the deltas, indicating the sign of entry / exit as a sign,
then start shedding bloody tears in situations where "twice threw , caught once" or "went out twice, then went in", "went in, but did not go out", etc.
a similar, but slightly more convenient option in terms of detection - using pivot, we decompose the timestamps into two columns, and then, as in the first option, deltas (only having the ability to filter out-entered)
ps from practice - a completely unpromising path if at the input there is no lock-mill under the supervision of two stern Vokhrovites.
A more promising option - you can offer a more detailed description of the original task / problem
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question