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

Sql 查询以查找过去一周注销时间>下午6点的所有记录,sql,postgresql,epoch,Sql,Postgresql,Epoch,我有一个名为logoninfo的数据库表。下面是模式 Record ID|User ID | Computer ID |LOGON_TIME|LOGOFF_TIME 登录和注销时间以毫秒为单位。所有用户将每天登录,同一用户和计算机将有多个条目,但记录ID不同。我需要找到过去一周下午6点后注销的所有记录。更具体地说,我需要知道所有在下午6点之后被视为过度停留的用户以及他们何时过度停留。请帮我解答这个问题。我正在使用PostgreSQL 9.5。您需要将可怕的纪元转换为适当的时间戳,

我有一个名为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';

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

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

登录和注销时间以毫秒为单位-在什么之后的毫秒?午夜之后?Unix时代?四月一日?为什么那不是一个时间戳或时间列?@a_horse_,没有名字,这是unix时代。由于内部依赖,我们不能使用时间戳或时间。是否可以进行上述查询?登录和注销时间以毫秒为单位-在什么之后的毫秒?午夜之后?Unix时代?四月一日?为什么那不是一个时间戳或时间列?@a_horse_,没有名字,这是unix时代。由于内部依赖,我们不能使用时间戳或时间。上述查询是否可行?