Lakukan GROUP BY
, gunakan COUNT
(yang hanya menghitung nilai bukan nol):
select id,
count(value1) as value1,
count(value2) as value2,
count(value3) as value3
from table1
group by id
Sunting :
Jika nilainya bukan nol tetapi '.' (atau yang lainnya), gunakan case
ekspresi untuk melakukan penghitungan bersyarat, seperti:
select id,
count(case when value1 <> '.' then 1 end) as value1,
count(case when value2 <> '.' then 1 end) as value2,
count(case when value3 <> '.' then 1 end) as value3
from table1
group by id