所需的输出-
https://www.dropbox.com/s/1mnrabcefvezt89/test11.png?dl=0

我正在尝试从Attend_Date的同一张表中加入这4个不同的查询,但我不知道该怎么做。
最终输出将为Attend_Date,P,A,MC(共4列)

SELECT Attendance.Attend_Date
FROM Student, Attendance
LEFT OUTER JOIN (
SELECT Attendance.Attend_Date, COUNT(Attendance.AttendDet_Type) as P
FROM Student, Attendance
WHERE Student.Stud_ID = Attendance.Stud_ID
AND Student.Stud_Class = '1A1'
AND Attendance.Attend_Date BETWEEN '2014-01-01' AND '2014-12-01'
AND Attendance.AttendDet_Type = 'P'
GROUP BY Attendance.Attend_Date
) ON Attendance.Attend_Date
WHERE Student.Stud_ID = Attendance.Stud_ID
AND Student.Stud_Class = '1A1'
AND Attendance.Attend_Date BETWEEN '2014-01-01' AND '2014-12-01'
GROUP BY Attendance.Attend_Date


谁能帮我吗?非常感谢!!

最佳答案

尝试在from语句中添加同一张表两次,然后将它们设置为变量名并正确重命名所有内容。例如,

FROM Student S1, Attendance A1
WHERE S1.Stud_ID = A1.Stud_ID


另一个

FROM Student S2, Attendance A2
WHERE S2.Stud_ID = A2.Stud_ID


问题是联接上的外部表和内部表有冲突,可能会导致您的问题

10-04 21:44