我想選擇其中用戶名和groupId重複的所有行,並且userId不是該userName/groupId組合的最大userId。這是我到目前爲止的代碼:相關查詢:選擇哪裏條件不是最大(條件在內部查詢)
select *
from userTable u
where exists
(select *
from userTable u1
where userName <> '' and userName is not null
and u.userName = u1.userName and u.groupId = u1.groupId
and u.userId <> max(u1.userId)
group by userName, groupId
having count(*) > 1)
order by userName
然而,該行:
and u.userId <> u1.max(userId)
是給我的錯誤。
什麼是正確的方法來做這個查詢?
A小調錯字,'u1.max(用戶ID)'應該是'MAX(u1.userId)',但我不認爲這將解決問題。 – rubish
@ Rubish-謝謝!我會編輯它來修復錯字。 – dmr