我有一個表審計登錄,我想提取每個用戶的最新登錄,下面的sql完成。使用group by子句和/或聚合函數將sql查詢轉換爲linq to sql?
我如何將sql查詢格式化爲一個linq到sql查詢?
SELECT * FROM AuditTable adt1
inner join UserTable usr
on adt1.[UserName] = usr.[User_Id]
WHERE [TimeStamp] = (SELECT MAX([TimeStamp])
FROM AuditTable adt2
WHERE adt1.UserName = adt2.UserName)
另一種在sql中編寫查詢的方法;
SELECT adt1.[UserName], usr.First_Name, max([TimeStamp]) as [TimeStamp]
FROM AuditTable adt1
INNER JOIN UserTable usr
on adt1.[UserName] = usr.[User_Id]
GROUP BY adt1.[UserName] ,usr.First_Name
謝謝,到底有沒有完整的答案在下面.. :-) – 2009-08-07 10:51:38