gpt4 book ai didi

SQL 查询 - Count() 和内部连接

转载 作者:行者123 更新时间:2023-12-04 16:08:19 25 4
gpt4 key购买 nike

当学生每周有超过 4 小时的时间时,我想使用内部联接列出学生 ID、姓名和每周安排的总小时数。

我这里需要三个表,student, studentReg 和 roomBooking 如下

 student

id | fname | surname | courseCode

studentReg

sID | modCode

roomBooking

bookingID | roomCode | moduleCode | dayReq | timeReq | semester | classSize

我目前的 SQL 查询是

 SELECT COUNT(moduleCode) AS [Lecture Hours],
id, fname, surname
FROM (student INNER JOIN studentReg ON student.id = studentReg.sID
INNER JOIN roomBooking ON studentReg.modCode = roomBooking.moduleCode)
HAVING COUNT (moduleCode) > 4;

当我尝试运行它时,我得到“表达式中的语法错误”

谁能帮我看看这是什么问题?

最佳答案

永远不确定在 ms Access 中嵌套连接,但我会尝试类似的东西

SELECT COUNT(moduleCode) AS [Lecture Hours],
id, fname, surname
FROM student
INNER JOIN (studentReg
INNER JOIN roomBooking ON studentReg.modCode = roomBooking.moduleCode)
ON student.id = studentReg.sID
GROUP BY id, fname, surname
HAVING COUNT (moduleCode) > 4

或者也许

SELECT COUNT(moduleCode) AS [Lecture Hours],
id, fname, surname
FROM (student INNER JOIN studentReg ON student.id = studentReg.sID)
INNER JOIN roomBooking ON studentReg.modCode = roomBooking.moduleCode
GROUP BY id, fname, surname
HAVING COUNT (moduleCode) > 4;

关于SQL 查询 - Count() 和内部连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26910803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com