Making a query with a single row out

You can do conditional aggregation :

select id,
       sum(case when type="x" and location = 'L' then amount else 0 end) as sumofXandL,
       . . . 
from table t
group by id;

Leave a Comment