繁体   English   中英

查询过去一周注销时间>下午6点的所有记录

[英]Query to find all the records where logoff time >6 PM for the past week

我有一个名为logoninfo的数据库表。 下面是架构。

       Record ID|User ID | Computer ID |LOGON_TIME|LOGOFF_TIME

登录和注销时间以毫秒为单位。 所有用户每天都会登录,同一用户和计算机会有多个条目,但记录 ID 不同。 我需要找到过去一周下午 6 点之后注销的所有记录。 更具体地说,我需要知道所有过度停留的用户(在下午 6 点后注销被视为过度停留)以及他们何时过度停留。 请帮我查询。 我正在使用 PostgreSQL 9.5。

您需要将可怕的时代转换为适当的时间戳,然后您可以轻松查询:

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';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM