当前为我的数据库而言,我希望找到至少有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;
我想知道是否有人知道为什么组功能不起作用,以及我应该如何检查对该工作感兴趣的用户?感谢任何可以提供帮助的人。
将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) > 10