Reputation: 3511
I have below data table and need to accomplish the result for Student count as per availability and per department
Note: Different Department may come in later.
Want to have result as below: (Student count as per availability and per department)
Upvotes: 0
Views: 35
Reputation: 46249
First you need to get count by department,studavailablity
on a subquery.then use GROUP_CONCAT
function to create the studCount by subquery.
If you want to show Yes
in front of No
you could Add order by
on GROUP_CONCAT
function.
You can try this.
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
Upvotes: 1
Reputation: 201
How about SELECT Department, Studavailability, COUNT(*) FROM students GROUP BY Department, Studavailability;
? Best of luck!
Upvotes: 0