我有一個用戶登錄的tblData。在表中它們可以是IN或OUT。 我要的是顯示當前登錄的用戶。在SqlServer中查詢用戶當前登錄
0
A
回答
1
Declare @a table ([Date] date,[Time] Time(7),[Type] varchar(10),ID int, Location int)
Insert into @a Select '20130101','10:00','IN',280,2
union Select '20130101','11:00','IN',280,2
union Select '20130101','12:00','OUT',280,2
union Select '20130101','12:00','IN',111,2
union Select '20130101','12:00','OUT',1,2
union Select '20130101','13:00','IN',1,2
Select * from @a a2
JOIN
(
Select MAX(Cast([Date] as dateTime)+[Time]) DT,ID
from @a
Group by ID
) b
on b.ID=a2.ID and Cast(a2.[Date] as dateTime)+a2.[Time] = b.DT
Where a2.Type='IN'
1
SELECT *
FROM tblData E
WHERE E.date = convert(date, getdate())
and convert(time, E.time) <= convert(time, getdate())
and E.type = 'IN'
not exists(
select 'x' from tblData U
where U.id = E.id
and U.type = 'OUT'
and E.date = U.date
and U.time > E.time
and convert(time, U.time) <= convert(time, getdate()))
0
SELECT
ID,MAX(convert(datetime,DATE)+' '+TIME) FROM tblData T1 WHERE [Type] = 'IN' AND convert(datetime,DATE)+' '+TIME>
(SELECT max(convert(datetime,DATE)+' '+TIME) FROM tblData T2 WHERE T1.ID=T2.ID AND [TYPE]='OUT')
GROUP BY
ID
UNION
SELECT
ID,convert(datetime,DATE)+' '+TIME FROM tblData T1 WHERE [Type] = 'IN' AND NOT EXISTS
(SELECT convert(datetime,DATE)+' '+TIME FROM tblData T2 WHERE T1.ID=T2.ID AND [TYPE]='OUT')
0
SELECT
ID,MAX(QDateTime) FROM tblData T1 WHERE [Type] = 'IN' AND QDateTime>
(SELECT max(QDateTime) FROM tblData T2 WHERE T1.ID=T2.ID AND [TYPE]='OUT')
GROUP BY
ID
UNION
SELECT
ID, QDateTime FROM tblData T1 WHERE [Type] = 'IN' AND NOT EXISTS
(SELECT QDateTime FROM tblData T2 WHERE T1.ID=T2.ID AND [TYPE]='OUT')
相關問題
- 1. Django的:在查詢列表當前登錄用戶
- 2. SqlServer:用戶登錄失敗
- 3. keystone.js當前登錄用戶
- 4. 通過SELECT查詢獲取當前登錄的用戶ID
- 5. 如何檢查當前登錄的用戶和登錄時間
- 6. 當前在stackmob登錄的用戶
- 7. 如何在MVC中查詢當前登錄用戶的AD信息4
- 8. 如何檢查當前PC用戶是否是當前登錄的用戶?
- 9. Nodejs檢查用戶在前端登錄
- 10. 當前登錄用戶的Teamcity屬性
- 11. 通知當前登錄的用戶
- 12. 顯示當前登錄用戶
- 13. pysvn:獲取當前登錄用戶名
- 14. 獲取當前登錄用戶
- 15. 創建只有當前登錄用戶
- 16. 當前登錄用戶的設置ID
- 17. QT獲取當前登錄用戶ID
- 18. 當前登錄用戶的CAS號碼
- 19. 當前用戶登錄詳細信息
- 20. Sails.js + Passport.js獲取當前登錄用戶
- 21. 爲當前登錄的用戶
- 22. 獲取當前登錄用戶PHP
- 23. 獲取當前登錄的Windows用戶?
- 24. Android Detect當前登錄用戶
- 25. Sed $顯示當前登錄用戶
- 26. 獲取當前登錄用戶asp.net
- 27. 獲取當前用戶名,即在SharePoint 2010門戶中登錄
- 28. 當前登錄用戶/管理員不能刪除本身(當前登錄的)
- 29. 更改燒瓶登錄當前登錄用戶
- 30. 登錄之前檢查用戶狀態
我想你應該只是使保持「IN」標識的另一個表和'Out'Id將記錄保存在tbldataRecords表中。 – Pakk