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 |
|
Kyriakos
Starting Member
13 Posts |
Posted - 2007-10-28 : 14:20:11
|
| For a set likeREGION SALESMAN LINE OF SALES AMOUNTA 1 Q 12A 2 R 13A 3 R 12A 3 Q 11A 1 S 9A 2 Q 12A 1 S 11A 3 R 5A 1 S 9A 2 Q 12B 4 S 11B 6 S 11B 4 Q 23B 4 S 3B 7 S 21B 6 Q 12B 5 S 14B 5 Q 12B 5 R 11I shall need to group by salesman but if the line of sales is Q, for all salesmen that belong to A region, their sales should be added to salesman #2 and for all salesmen that belong to B region, their sales should be added to salesman 6The output should be likeREGION SALESMAN LINE OF SALES AMOUNTA 1 Q 0A 1 S 29A 2 R 13A 2 Q 35A 3 R 17A 3 Q 0B 4 S 14B 4 Q 0B 5 S 14B 5 Q 0B 5 R 11B 6 S 11B 6 Q 47B 7 S 21Thanks for any help in advanceKyriakos |
|
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2007-10-28 : 14:29:49
|
| Select Region, Case When [Line of Sales] = 'Q' and Region = 'A' then 2 When [Region] = 'B' then 6 else [Salesman] end as Salesman,[Line of Sales], Sum(Amount) as SumAmountFrom [TableName]Group by Region, Case When [Line of Sales] = 'Q' and Region = 'A' then 2 When [Region] = 'B' then 6 else [Salesman] end,[Line of Sales]Untested. |
 |
|
|
|
|
|