I'm trying to do a group by like this, but I don't get the result I want. I would like the result to be in a single row. I hope you can help me.
Select GUIA_DET_NRO_REF,
case car_ind_fc when 0 then count(car_ind_fc) end AS pendientes,
case car_ind_fc when 1 then count(car_ind_fc) end AS facturadas,
case car_ind_fc when 2 then count(car_ind_fc) end as Anuladas
from guia_DEtalle_nacional gdn with(nolock)
group by GUIA_DET_NRO_REF,car_ind_fc
What you're looking for is a conditional count:
Grades
COUNT()
GUIA_DET_NRO_REF