我只想为u.classno,u.userno选择具有最大b.enddate的行。但这是行不通的。

select u.classno, u.userno, b.enddate
from libUser u
join book b on b.id = u.bookid
group by u.classno, u.userno
having b.enddate=max(b.enddate) //doesn't works

最佳答案

有什么问题:

select u.classno, u.userno, MAX(b.enddate)
from libUser u
join book b on b.id = u.bookid
group by u.classno, u.userno

关于sql - 通过连接表最大值选择仅行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18694094/

10-13 08:37