Lav en GROUP BY
, brug COUNT
(som kun tæller ikke-nullværdier):
select id,
count(value1) as value1,
count(value2) as value2,
count(value3) as value3
from table1
group by id
Rediger :
Hvis værdierne ikke er null, men '.' (eller noget andet), brug case
udtryk for at udføre betinget tælling, noget som:
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