我有一个关于distinct和group by的问题,请帮帮我
KTP KECAMATAN
1111111 PARIAMAN
1111111 PARIAMAN
2222222 PAYAKUMBUH
1111111 PAYAKUMBUH
我想要像这样的结果
KECAMATAN KTP TOTAL
PARIAMAN 1111111 2
PAYAKUMBUH 1111111 1
PAYAKUMBUH 2222222 1
select KTP, KECAMATAN, COUNT(distinct KTP) as TOTAL
from TABLE_A
group by kecamatan
答案 0 :(得分:1)
试试这个:
SELECT KTP, KECAMATAN, COUNT(KECAMATAN) as TOTAL
FROM TABLE_A
GROUP BY KTP,KECAMATAN;