Given 3 tables in my database (prodi
, mahasiswa
and status
), I'm trying to output results grouped and counted.
Query
SELECT
prodi.namaprodi,
(case when count(`status`.idsm)='1' then 1 else 0 end) as '1',
(case when count(`status`.idsm)='2' then 1 else 0 end) as '2',
(case when count(`status`.idsm)='3' then 1 else 0 end) as '3',
(case when count(`status`.idsm)='4' then 1 else 0 end) as '4',
(case when count(`status`.idsm)='5' then 1 else 0 end) as '5',
(case when count(`status`.idsm)='6' then 1 else 0 end) as '6',
(case when count(`status`.idsm)='7' then 1 else 0 end) as '7',
(case when count(`status`.idsm)='8' then 1 else 0 end) as '8'
FROM
`status`
INNER JOIN mahasiswa ON mahasiswa.idm = `status`.idm
INNER JOIN prodi ON prodi.idp = mahasiswa.idp
GROUP BY
prodi.idp, `status`.idm
Actual Result
Hukum 0 1 0 0 0 0 0 0
Hukum 0 0 0 0 0 1 0 0
Hukum 0 1 0 0 0 0 0 0
Ekonomi 0 0 0 1 0 0 0 0
Ekonomi 0 0 0 1 0 0 0 0
Desired result
Hukum 0 2 0 0 0 1 0 0
Ekonomi 0 0 0 2 0 0 0 0
Any ideas how to get this query to work?