【发布时间】:2019-04-24 14:59:45
【问题描述】:
我需要根据以下问题创建一个查询:
我需要添加具有相同 zip 的教师和学生的数量,如果超过 10 则列出城市、州、教师总数、学生总数以及添加教师和学生的总数学生在一起。 所有三个表都有它们共享的 zip 字段。它是邮政编码表中的主键,也是教师和学生表中的外键。城市和州字段位于邮政编码表中。我最初有这个查询,但没有返回任何行。我无法得到总数。每次我合并 SUM 或加法时,我都会收到 ORA 00923 From keyword not found where expected 错误。
select city, state, 'TOTAL'
from zipcode
left join
(select student.zip, count(*) 'Total_Stud'
from student
group by zip)
s on zipcode.zip=student.zip
left join
(select instructor.zip, count(*) 'Total_Inst'
from instructor
group by zip)
i on zipcode.zip=instructor.zip
where count(student.student_id) + count(instructor.instructor_id)>=10 as total
order by total desc;
涉及 3 个表 学生表、教师和邮政编码
【问题讨论】:
-
在您提出下一个问题之前,我建议您阅读以下内容:Provide a
Minimal Complete Verifiable Example(MCVE) 和 Why should I provide a MCVE