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 |
|
gsi
Starting Member
4 Posts |
Posted - 2003-03-27 : 14:01:14
|
| Hello All,I am novice so need some help to build a query in MSSQL 2000. Below are the detailsA table contains the following fieldsprog_iditem_idtypeamountprod_id and item_id are the primary keys hereRows are to be summarized by program_id, and depending on the type, it needs to be summed up under total-A or Other Case type='A' then sum it up as total-Aelse any other type sum it up as Otherresults should be as follows:Prog_id total-A Other------------------------------------------123 $100.00 $300.00456 $150.00 $200.00 Any help will be appreciatedThanks gsiEdited by - gsi on 03/27/2003 14:10:55 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-03-27 : 14:25:43
|
| select program_id, SUM(CASE WHEN type='A' THEN amount else 0 end) as TotalA, SUM(CASE WHEN type<>'A' THEN amount else 0 end) as Otherfromyourtablegroup by program_id- Jeff |
 |
|
|
gsi
Starting Member
4 Posts |
Posted - 2003-03-27 : 14:40:29
|
| Thanks Jeff, that worked |
 |
|
|
|
|
|