答案 0 :(得分:1)
首先,您需要在子查询上按department,studavailablity
计数。然后使用GROUP_CONCAT
函数通过子查询创建 studCount 。
如果您想在Yes
前面显示No
,可以在order by
功能上添加GROUP_CONCAT
。
你可以试试这个。
SELECT department,GROUP_CONCAT(Concat(studavailablity,' ',c) order by 1 DESC) 'count'
FROM(
SELECT count(1) c,department,studavailablity
FROM T
GROUP BY studavailablity,department
) t
group by department
order by department desc
sqlfiddle:http://sqlfiddle.com/#!9/c4e56f/16
答案 1 :(得分:0)
SELECT Department, Studavailability, COUNT(*) FROM students GROUP BY Department, Studavailability;
怎么样?祝你好运!