查询以查找过去一周注销时间> 6 PM的所有记录

问题描述 投票:0回答:1

嗨,我有一个名为logoninfo的数据库表。下面是模式。

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

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

谢谢

sql postgresql epoch
1个回答
0
投票

您将需要将可怕的时期转换为正确的时间戳,然后可以轻松地查询:

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';
© www.soinside.com 2019 - 2024. All rights reserved.