0

Hi, everyone...
I have a question about sql ..

Question:

Customer | jan-april | may - august| september - december

A |quantity | |

B | | |

C | | |


How to use the SELECT command to retrieve data and the output is show like above.
please give me some examples.

Edited by Dumb Fish: n/a

5
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by Netcode
0

change your columns names accordingly

select customer, sum(case when month(datecolname) in (1,2,3) then quantity else 0 end) jan_mar
sum(case when month(datecolname) in (4,5,6) then quantity else 0 end) apr_jun,
sum(case when month(datecolname) in (7,8,9) then quantity else 0 end) jul_sep,
sum(case when month(datecolname) in (10,11,12) then quantity else 0 end) oct_dec
from tablename
where  month(getdate())=2011
group by customer

Edited by urtrivedi: n/a

0

urtrivedi's script should work, provided that the where is :

where year(datecolname) = '2011'

or something similar.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.