SELECT DISTINCT u.UserID, UserLastName, UserFirstName, UserName, Notified,
MAX (CycleNumber) as CycleNumber, (CycleCurrentStep) as CycleCurrentStep,
MAX (CycleDateReported) as CycleDateReported,
max (cycleid)
FROM [User] u
left join Cycle c on (u.UserID = c.UserID)
join UserDivSection us on (u.UserID = us.UserID
and us.DivSectionID=26)
group by u.UserID, UserLastName, UserFirstName, UserName, Notified, c.CycleCurrentStep
UserID UserLastName UserFirstName UserName Notified CycleNumber CycleCurrentStep CycleDateReported
290 Williams Craig [email protected] 1 7 0 208
290 Williams Craig [email protected] 1 9 3 210
290 Williams Craig [email protected] 1 7 5 1/29/2010 3:06:23 PM 204
290 Williams Craig [email protected] 1 8 6 2/1/2010 9:26:40 AM 209
我們正在努力恢復與最大cyclenumber該用戶ID匹配的唯一不重複的用戶ID行。現在,查詢對於不同的循環號返回相同的用戶標識多次。我們並不確定如何繼續進行正確的查詢。任何幫助,將不勝感激。幫助我們解決這個問題的SQL語句
'(CycleCurrentStep)'之前是否有MAX丟失? – Greg
基本上,您需要做的是運行一個查詢,獲取每個用戶的最大值(CycleNumber),然後加入到其中以獲取有關該特定User/CycleNumber組合的其餘數據 – Leslie