【发布时间】:2014-09-02 19:39:45
【问题描述】:
我有一个看起来像这样的表,名为new_attendance
Student_id | Attendance | Date | Class |Subject
-----------------------------------------------
2010639201 | No | 1/10/2014 | Lecture | CSC435
2010639202 | Yes | 3/10/2014 | Tutorial | CSC240
2010639203 | Yes | 10/10/2014 | Tutorial | CSP650
2010639201 | No | 2/10/2014 | Lab | CSC520
2010639201 | No | 4/10/2014 | Tutorial | ITT545
2010639204 | No | 5/10/2014 | Tutorial | CSP600
2010639205 | No | 6/10/2014 | Tutorial |ITT550
2010639206 | No | 7/10/2014 | Lab | CSC520
如何编写 SQL 计数查询来计算缺勤人数(出席人数 =“No”)和班级人数?
预期输出:
Student_id|No of absent|% of Absent|
------------------------------------
2010639202|3|3.57%
公式:
% of absent= ((no absent* (Lab+ Tutorial+ Lecture) ) / (14* subject_contachour) *100
【问题讨论】:
-
能否提供预期的输出?