这是我的查询:
SELECT Cottage15.CNUM,Cottage15.Rent,Assignment15.Hours
FROM Cottage15
INNER JOIN Assignment15
ON Cottage15.CNUM=Assignment15.CNUM
ORDER BY Assignment15.AID;
它可以工作,但我不知道如何将 Max
函数应用于 hours
?我希望 MAX(Assignment15.Hours)
能够工作!?
此查询显示所有行,但我只希望它显示基于小时字段具有最高数字的某些行。
最佳答案
您必须添加组聚合才能应用 Max 函数
SELECT Cottage15.CNUM,Cottage15.Rent,Max(Assignment15.Hours)
FROM Cottage15
INNER JOIN Assignment15
ON Cottage15.CNUM=Assignment15.CNUM
group by Cottage15.CNUM,Cottage15.Rent
ORDER BY Assignment15.AID;
关于sql - 如何在SQL中使用MAX函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29572165/