SQL month summary query statement select pencil as [month], sum (casemonth (date) when1then pencil else0end) as [January], sum (casemonth (date) when2then pencil else0end) as [February], sum (casemonth (date) when3then pencil else0end) a SQL month summary query statement
Select 'pencil 'as [month],
Sum (case month (date) when 1 then pencil else 0 end) as [January],
Sum (case month (date) when 2 then pencil else 0 end) as [February],
Sum (case month (date) when 3 then pencil else 0 end) as [March],
Sum (case month (date) when 4 then pencil else 0 end) as [April],
Sum (case month (date) when 5 then pencil else 0 end) as [May],
Sum (pencil) as total price
From table
Union all
Select 'pen 'as [month],
Sum (case month (date) when 1 then pen else 0 end) as [January],
Sum (case month (date) when 2 then pen else 0 end) as [February],
Sum (case month (date) when 3 then pen else 0 end) as [March],
Sum (case month (date) when 4 then pen else 0 end) as [April],
Sum (case month (date) when 5 then pen else 0 end) as [May],
Sum (PEN) as total price
From table
Result
The total price of a pencil from January 1, to January 1
Pencil 200 500 600 700 500 2500
Pen 200 300 250 400 300 1450
Brush set 300 400 500 300 600
Total price 700 1200 1350 1400 1400