Consider two tables student(ssn, name, major) and transcript(ssn,grade)
where ssn is primary key in student and foreign key in transcript. How do we find the students who received A in at least two transcripts with major CS. I have tried using having, group by to get the solution, but we shouldn't use group by and having. For three I have just replaced with the number at the end. Thank you for the answer in advance.
SELECT
s.ssn,
s.name,
s.major
FROM student s
INNER JOIN (
SELECT
ssn,
COUNT(grade) as number_of_grades
FROM transcript
WHERE grade = 'A'
GROUP BY ssn
) grade_count
ON grade_count.ssn = s.ssn
WHERE grade_count.number_of_grades >= 2
2条答案
按热度按时间jaql4c8m1#
只有几个变体:
第一个
注:CBO可以决定去相关你的横向(外部应用)加入分组依据。见“横向视图去相关”转换。
ev7lccsx2#
您可以两次连接到脚本表: