您好我需要通过加入两个查询来生成一个 sql 查询
第一个查询:获取所有学生数据
SELECT * FROM students where class = 1 and section = 'A'
第二个查询:获取每个出席人数
SELECT roll_no,full_name,
SUM(hasAttended= 'P') AS DaysPresent,
SUM(hasAttended= 'A') AS DaysAbsent,
COUNT(*) AS totalClasses
FROM attendance
GROUP BY roll_no
现在我需要加入这两个表并生成一个结果表
我正在尝试以下查询,但出现错误:
1248 - 每个派生表都必须有自己的别名
我的查询如下:
SELECT * FROM students as st
INNER JOIN
(SELECT att.roll_no,att.full_name,
SUM(att.hasAttended= 'P') AS DaysPresent,
SUM(att.hasAttended= 'A') AS DaysAbsent,
COUNT(*) AS totalClasses
FROM attendance as att
GROUP BY att.roll_no)
ON st.roll_no = att.roll_no
ORDER BY st.roll_no
有人可以解决上述错误吗