0

我使用了以下查询:

select tblclass.classname,tblattendance.id 
 from tblclass,tblattendance
where tblclass.classcode=tblattendance.classcode 
  and tblattendance.attdate='2013-07-01'

此查询的输出如下:

在此处输入图像描述

现在我想要的是而不是上面的结果,我想要计算不同的类别,如 IB-2、IC-5。请告诉我需要在查询中进行哪些修改才能获得所需的结果

4

3 回答 3

3

使用Group By SQL 子句并添加聚合函数Count

select tblclass.classname, Count(tblattendance.id) as counter 
from tblclass,tblattendance 
where tblclass.classcode=tblattendance.classcode and tblattendance.attdate='2013-07-01'
group by tblclass.classname
于 2013-09-24T07:48:18.957 回答
0

尝试这个

select count(tblattendance.id),tblclass.classname from tblclass,tblattendance 
where tblclass.classcode=tblattendance.classcode and tblattendance.attdate='2013-07-01' 
group by tblclass.classname
于 2013-09-24T07:49:07.840 回答
0

使用COUNT()功能与GROUP BY. 也使用JOIN.

SELECT tc.classname, COUNT(tc.classname) AS COUNTS
  FROM tblclass tc 
  JOIN tblattendance tt
    ON tc.classcode = tt.classcode
 WHERE tt.attdate='2013-07-01'
 GROUP BY tc.classname
于 2013-09-24T07:50:01.830 回答