user3487681
user3487681

Reputation: 149

view data from database table

SELECT dun, COUNT( id_ahli ) AS JUMLAH_KESELURUHAN, COUNT(kaum='melayu') AS melayu, COUNT(kaum='cina') AS cina 
FROM maklumat_ahli
WHERE jantina = 'lelaki'
AND 
(kematian_tarikh IS NULL)
AND (bayaran_pertama IS NULL)
AND (bayaran_kedua IS NULL)
GROUP BY dun
ORDER BY dun

this is my sql statement. Is it posible to count and view data by kaum?. i use that sql statement, but my count is not correct

/-----------------------------------------/
|dun | Jumlah_keseluruhan | melayu | cina |
-------------------------------------------
|A   |123                 |100     |23    |
-------------------------------------------

is it any possible way to view data from db like the table above.

Upvotes: 0

Views: 45

Answers (1)

MikkaRin
MikkaRin

Reputation: 3084

To count data by special value you may use CASE clause

COUNT(case when kaum='melayu' then 1 else 0 end) AS melayu, 
COUNT(case when kaum='cina'the 1 else 0 end) AS cina

Upvotes: 2

Related Questions