我有一个名为logoninfo的数据库表。下面是模式。
Record ID|User ID | Computer ID |LOGON_TIME|LOGOFF_TIME登录和注销时间以毫秒为单位。所有的用户将每天登录,将有相同的用户和计算机,但不同的记录ID的多个条目。我需要找到过去一周下午6点后注销的所有记录。更具体地说,我需要知道所有过度停留的用户(下午6点后注销,被视为过度停留)以及他们何时过度停留。请帮我解决这个问题。我使用的是PostgreSQL 9.5。
发布于 2020-05-14 14:02:19
您需要将可怕的纪元转换为适当的时间戳,然后您可以很容易地查询:
select *
from the_table
where
-- this selects every row where logged off is after 18:00
to_timestamp(logoff_time)::time > time '18:00'
-- the following two conditions select all rows from last week
and to_timesamp(logoff_time) >= date_trunc('week', current_timestamp) - interval '1 week'
and to_timesamp(logoff_time) < date_trunc('week', current_timestamp) - interval '1 week' + interval '1 week';https://stackoverflow.com/questions/61790113
复制相似问题