简体   繁体   English

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

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

I have a Database Table named logoninfo .我有一个名为logoninfo的数据库表。 Below is the schema.下面是架构。

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

The Logon and logoff time are in milliseconds.登录和注销时间以毫秒为单位。 All the users will logon daily and there will be multiple entries for same user and computer but different Record ID.所有用户每天都会登录,同一用户和计算机会有多个条目,但记录 ID 不同。 I need to find all the records that logged off after 6 PM on the past week.我需要找到过去一周下午 6 点之后注销的所有记录。 To be more specific I need to know all the users who over stayed (logged off after 6 PM considered as Over stayed) and when they over stayed.更具体地说,我需要知道所有过度停留的用户(在下午 6 点后注销被视为过度停留)以及他们何时过度停留。 Help me with the query please.请帮我查询。 I'm using PostgreSQL 9.5.我正在使用 PostgreSQL 9.5。

You will need to convert the dreaded epoch into a proper timestamp, then you can easily query that:您需要将可怕的时代转换为适当的时间戳,然后您可以轻松查询:

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