我的表格如下:
ID_USER USERNAME_USER REF_USER STATUS_AKTIF
1 a aktif
2 b a tidak
3 c a aktif
4 d b aktif
5 e a aktif
我使用这段代码:
select REF_USER, count(distinct USERNAME_USER) as TOTAL from TABLE where (REF_USER IS NOT NULL AND REF_USER!="" AND STATUS_AKTIF='aktif') group by REF_USER
但我只得到:
REF_USER TOTAL
a 2
b 1
我怎么能删除b?因为用户b STATUS_AKTIF是tidak
答案 0 :(得分:0)
只需按
添加一个组SELECT count(*) as total, username_user FROM table
WHERE (REF_USER IS NOT NULL AND REF_USER!="" AND STATUS_AKTIF='aktif')
GROUP BY username_user