Torna al Thread
select codcomune, comune, codiceordinaento, sum(totstrutture) as totstrutture, sum(totcamere) as totcamere, sum(totletti) as totletti, sum(totbagni) as totbagni from
(
select codcomune,comune,codiceordinamento,count(codiceordinamento) as totstrutture,
totcamere,totletti,totbagni
from #prova
group by codcomune, comune, CodiceOrdinamento,
totcamere, totletti, totbagni
) as temp
group by codcomune, comune