Sabtu, 25 Agustus 2012

group by

Group by statement on sql server often use to show some field with one or more of them contain number which will be summed.

We still use example previous post, with small modification.

select product_name,SUM(qty)qty from (
    select 'book notes'product_name,(4)qty union
    select 'pencil',(15) union
    select 'book notes',(3) union
    select 'pencil',(10)
)view1 group by product_name order by product_name 


#Results:
product_name    qty
book notes        7
pencil           25 

Tidak ada komentar:

Posting Komentar