------------------------------------------------------------------ Itemcode | DocType | Qty | ------------------------------------------------------------------ 100011 | FA | 100 | 100011 | FA | 50 | 100011 | AJN | 10 | 100011 | FA | 100 | 100011 | AJN | 50 | -----------------------------------------------------------------
нужен результат
------------------------------------------------------------------ Itemcode | FA | AJN | ------------------------------------------------------------------ 100011 | 250 | 0 | 100011 | 0 | 60 | -----------------------------------------------------------------
Попробуйте, вот демоверсия .
select Itemcode, sum(case when DocType = 'FA' then Qty end) as FA, sum(case when DocType = 'AJN' then Qty end) as AJN, from yourTable group by Itemcode