0

我很难在一个学生正在学习的列中显示班级数量。

我有以下查询,但我不确定 COUNT 到底是什么计数以及如何显示每个学生的计数:

CREATE VIEW Busy_Student AS
SELECT First_Name, Last_Name, Student.Student_ID
FROM Student 
INNER JOIN Enrollment ON Enrollment.Student_ID= Student.Student_ID
GROUP BY Student.Student_ID, Student.First_Name, Student.Last_Name 
HAVING COUNT(*) > 2

创建一个视图调用 BUSY_STUDENT,它存储连接的名称(名字和姓氏)、学生 ID 和注册的班级数量,用于注册超过 2 个班级的所有学生。分别命名这些列,FULL_NAME、STUDENT_ID 和 ENROLL_NUM。

4

2 回答 2

0

你的 SELECT 语句应该是这样的:

SELECT First_Name + ' ' + Last_Name AS [FULL_NAME],
Student.Student_ID, COUNT(*) AS [ENROL_NUM]
FROM Student 
INNER JOIN Enrollment ON Enrollment.Student_ID= Student.Student_ID
GROUP BY Student.Student_ID, Student.First_Name, Student.Last_Name 
HAVING COUNT(*) > 2
于 2013-04-05T00:01:50.710 回答
0

你非常接近它:

CREATE VIEW Busy_Student AS
SELECT
    CONCAT(First_Name, ' ', Last_Name) AS FULL_NAME,
    Student.Student_ID AS STUDENT_ID,
    COUNT(Enrollment.Enrollment_id) AS ENROLL_NUM
FROM Student 
INNER JOIN Enrollment USING(Student_ID)
GROUP BY Student.Student_ID
HAVING ENROLL_NUM > 2

计数是根据Enrollment与学生 ID 匹配的行数进行的。由于您只给出了内部连接列,因此我假设每个注册都由该列唯一标识Enrollment_id。您应该根据您的架构调整该列名。

利用

First_Name + ' ' + Last_Name AS FULL_NAME 

对于 SQL 服务器。

于 2013-04-05T00:11:38.747 回答