目前,对于我的数据库,我希望找到工作,其中至少有10个感兴趣的用户。我想要它显示的jobNum,标题和感兴趣的用户总数。我的群组功能有问题,我不知道如何检查10个用户。
(PK) = Primary Key
(FK) = Foreign Key数据库模式如下:
Building(buildingNum(PK), Description, instname, buildName, state, postcode)
User(UNum(PK), buildingNum(FK), Surname, FirstName, initials, title)
File(FileNum(PK), title)
UserAccount(FileNum(PK)(FK), UNum(PK)(FK))
Job(JobNum(PK), id, title)
Interest(JobNum(PK)(FK), UNum(PK)(FK), Description)到目前为止,我已经尝试了以下代码块:
select J.JobNum, J.title, count(I.UNum)
from Job J join Interest I
where I.JobNum = J.JobNum and count(I.UNum) > 10
group by J.JobNum, J.title;我想知道是否有人知道为什么组函数不工作,以及我应该如何检查有多少用户对这项工作感兴趣?感谢任何能帮上忙的人。
发布于 2019-05-22 15:58:19
将count()条件移动到HAVING子句。JOIN需要用于联接条件的ON子句,而不是WHERE子句。
select J.JobNum, J.title, count(I.UNum)
from Job J join Interest I
ON I.JobNum = J.JobNum
group by J.JobNum, J.title
having count(I.UNum) > 10https://stackoverflow.com/questions/56251901
复制相似问题