计数 - 基于两个表的输出
Counting - based on output from two tables
我有两个表:master 和 class。 Master 是所有曾就读于该学校并具有学生 ID 和社会安全号码 (SSN) 的学生的主列表。我担心优等生被分配了多个学生证。我想计算每个 SSN 的学生 ID。
select master.studentID, master.SSN, class.studentID, class.type
from master, class
where master.studentID = class.student.ID and class.type = 'Honors" and count(master.StudentID) > 1
我收到以下错误消息:"Use of function COUNT not valid"
select master.SSN
from master
join class on master.studentID = class.student.ID
where class.type = 'Honors'
group by master.SSN
having count(distinct master.studentID) > 1
只需将您的 where 子句谓词转换为子查询
select m.studentID, m.SSN, c.studentID, c.type,
(Select count(*) from master
Where SSN = m.SSN) ssnCount
from master m join class c on c.studentID = m.studentID
where c.type = 'Honors"
and (Select count(*) from master
where SSN = m.SSN) > 1
我有两个表:master 和 class。 Master 是所有曾就读于该学校并具有学生 ID 和社会安全号码 (SSN) 的学生的主列表。我担心优等生被分配了多个学生证。我想计算每个 SSN 的学生 ID。
select master.studentID, master.SSN, class.studentID, class.type
from master, class
where master.studentID = class.student.ID and class.type = 'Honors" and count(master.StudentID) > 1
我收到以下错误消息:"Use of function COUNT not valid"
select master.SSN
from master
join class on master.studentID = class.student.ID
where class.type = 'Honors'
group by master.SSN
having count(distinct master.studentID) > 1
只需将您的 where 子句谓词转换为子查询
select m.studentID, m.SSN, c.studentID, c.type,
(Select count(*) from master
Where SSN = m.SSN) ssnCount
from master m join class c on c.studentID = m.studentID
where c.type = 'Honors"
and (Select count(*) from master
where SSN = m.SSN) > 1