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 |
kashyap81
Starting Member
9 Posts |
Posted - 2008-06-07 : 02:09:07
|
so lets say I have a tableTAD_ITEM_DETAILS ->ItemID ComponentType Price------------------------------1 1 1001 1 2001 2 502 1 1003 2 100...I want a select statement that does something like this:select itemid, sum(price) as TotalItemPrice, sum(price of componenttype=1) as TotalPriceComponentType1from TAD_ITEM_DETAILSgroup by itemidOutput:ItemID TotalItemPrice TotalPriceComponentType11 350 3002 100 1003 100 0The problem is... I cant find a good way to do sum(price of componenttype=1)any ideas?DiaTree.comD.I.P. Pvt Ltd |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-07 : 03:20:53
|
selectitemid,sum(price) as TotalItemPrice,sum(case when componenttype=1 then price else 0 end) as TotalPriceComponentType1fromTAD_ITEM_DETAILSgroup byitemid E 12°55'05.25"N 56°04'39.16" |
 |
|
kashyap81
Starting Member
9 Posts |
Posted - 2008-06-07 : 06:36:32
|
That worked.Thank you.DiaTree.comD.I.P. Pvt Ltd |
 |
|
|
|
|