2016-11-13 62 views
0

如何将此查询转换为使用条件的嵌套查询?将连接查询转换为嵌套查询

SELECT schedule.subcode,attendance.usn,AVG(attendance.ispresent)* 100作为Attendance_Percentage FROM时间表JOIN出勤ON schedule.sched_id = attendance.sched_id WHERE USN = “4jc14is013” 和子码= “is530”;

+1

'HAVING AVG(ispresent)<0.75' –

+1

你的数据库格式不正常的形式。它应该是两个表格: '人(usn,name)'和'存在(日期,usn)'。请参阅https://www.tutorialspoint.com/dbms/database_normalization.htm – lovasoa

回答

0

您可以使用HAVING

SELECT usn, name, AVG(ispresent) attendance FROM table 
GROUP BY usn, name HAVING attendance < 0.75; 
+2

您忘记了GROUP BY子句 –

+0

已添加。谢谢 –

+0

谢谢先生@PaulSpiegel –