|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
thanks for the help in advance.
i have the following table productid gross net 64 $288,450.80 $248,445.25 71 $2,810.18 $2,413.98 63 $9,403.50 $9,272.37 58 $66,698.37 $60,729.74 56 $4,404.11 $4,281.16 52 $31,599.07 $29,509.35 some of these productids are related. i am trying to sum the related ones. like sum the gross for 64 and 63, sum the gross for 56 and 52 so that i will get $297854,30 total gross for 64 and 63. how do i do this? thanks in advance |
|
#3
|
|||
|
|||
|
this is how i did it...
SELECT sum(case productid when 63 then Gross when 64 then gross end) as prd1, sum(case productid when 56 then Gross when 52 then gross end) as prd2, sum(case productid when 58 then gross end) as prd3, sum(case productid when 71 then gross end) as prd4 FROM SubCount another question i have is this query results in something like prd1 prd2 prd3 prd4 333 2222 111 9999 is there a way to rearrange the output so that it will display it as product gross ------- ---- prd1 333 prd2 2222 prd3 111 prd4 9999 ![]() |
|
#4
|
||||
|
||||
|
Quote:
Code:
select 'prd1' as product
, sum(gross) as gross
from SubCount
where productid in (63,64)
union all
select 'prd2' as product
, sum(gross) as gross
from SubCount
where productid in (52,56)
union all
select 'prd3' as product
, sum(gross) as gross
from SubCount
where productid in (58)
union all
select 'prd4' as product
, sum(gross) as gross
from SubCount
where productid in (71)
order by 1
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > query help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|