Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
freshman11
Starting Member
13 Posts |
Posted - 2011-07-27 : 06:45:18
|
| hi i have a table with 5 columns (area, customer_code, customer_name, doc_date, total_cost). The challenge is to extract the month in doc_date and sum up the total cost per month. the query should be able to retrieve total_cost per cusotmer, monthly for every year. customer_code customer_name Jan Feb Mar April . . . . . thanks in advance! |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-07-27 : 06:55:08
|
selectcustomer_code,max(customer_name) as customer_name,Year(doc_date) as Year,Month(doc_date) as Month,sum(total_cost) as total_costfrom YourTablegroup by customer_code,Year(doc_date),Month(doc_date) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
freshman11
Starting Member
13 Posts |
Posted - 2011-07-27 : 07:15:21
|
| hi webfred! thanks for the reply :)i think the query would retrieve it by rows, i need the months to be retrieved in columns also with the sum of sales monthly per customer. :( |
 |
|
|
freshman11
Starting Member
13 Posts |
Posted - 2011-07-27 : 07:34:10
|
| need help. need to retrieve data, extracted from date as columns and rows should have the sales per customer. |
 |
|
|
|
|
|
|
|