簡體   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