次の行を含むテーブルがあります。
NAME RFID ACTION TIME DATE
Kashif Islam E2001026770D00742340248A OUT 12:40:00 1/30/2013
Dr.Arshad Ali Shahid E2001026770D0212267009D3 IN 13:52:00 1/30/2013
Qasim Mehmood E2001026770D018223202774 IN 13:52:00 1/30/2013
M.Bilal Khan E2001026770D009522402D80 IN 13:52:00 1/30/2013
Abdul Hameed E2001026770D0181248019B8 IN 13:52:00 1/30/2013
Usman Tariq E2001026770D00862570111D IN 13:52:00 1/30/2013
Dr. Asif Gondal E2001026770D012426600B32 IN 13:52:00 1/30/2013
Dr.Arshad Ali Shahid E2001026770D0212267009D3 OUT 13:52:00 1/30/2013
Dr.Arshad Ali Shahid E2001026770D0212267009D3 IN 13:53:00 1/30/2013
Dr.Arshad Ali Shahid E2001026770D0212267009D3 OUT 13:53:00 1/30/2013
Dr.Arshad Ali Shahid E2001026770D0212267009D3 IN 13:53:00 1/30/2013
Dr.Arshad Ali Shahid E2001026770D0212267009D3 OUT 13:53:00 1/30/2013
Dr.Arshad Ali Shahid E2001026770D0212267009D3 IN 13:54:00 1/30/2013
Dr.Arshad Ali Shahid E2001026770D0212267009D3 OUT 13:54:00 1/30/2013
Aamir Hafeez E2001026770D01952510155B IN 13:55:00 1/30/2013
Amjad Ali Anjum E2001026770D024125401476 IN 13:55:00 1/30/2013
Amjad Ali Anjum E2001026770D024125401476 OUT 13:56:00 1/30/2013
Dr. Asif Gondal E2001026770D012426600B32 OUT 13:56:00 1/30/2013
Arif Shah E2001026770D01852370206D IN 13:56:00 1/30/2013
Fida ul Hassan E2001026770D02112720095C IN 13:56:00 1/30/2013
ACTION
今、私は各人の特定の日付の最新情報を取得したいと考えています。
1/30/2013 13:56:00 OUT Amjad Ali Anjum
1/30/2013 13:56:00 IN Arif Shah
1/30/2013 13:56:00 OUT Dr. Asif Gondal
1/30/2013 13:54:00 OUT Dr.Arshad Ali Shahid
1/30/2013 13:56:00 IN Fida ul Hassan
以下のクエリを使用して取得していますが、正しい結果が得られません。
WITH CTE AS (
SELECT
row_number() over (partition by personname order by date) rn,
date,action,time,
personname
FROM
AISDb)
SELECT date,time,action,
personname
FROM CTE WHERE RN = 1 AND datestamp = '1/30/2013'