我需要在MySQL表格中显示特定学生的月度出勤报告。我需要下面的结果,
我的数据库中有考勤表,如下图所示:
我想从我的考勤表中获取数据,其中备注' 1'意味着'现在' 如下: 我需要MySQL查询来获取如下所示的数据
请任何人帮我写查询
我的查询是
SELECT YEAR(att_date) AS y, MONTH(att_date) AS m, COUNT(DISTINCT att_date) FROM attendance WHERE class_id=11 AND student_id=15 GROUP BY y, m
但是没有得到预期的结果,如下所示
student-ID-15
CLASS STUDENT_ID YEAR MONTH TOTAL_CLASSES TOTAL_PRESENT
11 15 2016 April 21 20
11 15 2016 May 25 25
11 15 2016 June 30 29
11 15 2016 July 18 18
11 15 2017 January 28 28
答案 0 :(得分:0)
SQLFiddle:here
SELECT
YEAR(att_date) AS `YEAR`,
MONTHNAME(att_date) AS `MONTH`,
COUNT(DISTINCT att_date) as TOTAL_CLASSES,
COUNT(DISTINCT IF(remarks != '0'
AND class_id=@class_id
AND student_id=14,
att_date, NULL)) as TOTAL_PRESENT
FROM attendance CROSS JOIN (SELECT @class_id :=
(SELECT class_id FROM attendance WHERE student_id = 14 LIMIT 1)) param
GROUP BY `YEAR`, MONTH(att_date);
答案 1 :(得分:0)
http://sqlfiddle.com/#!9/ae54c95/1
<select class="form-control" data-ng-model="model" data-ng-options="availabledevice.model for availabledevice in availabledevices|filter:make.make" required></select>