BrianTyler
IS-IT--Management
I am trying to understand some of the OLAP functions available in DB2.
Consider a table with three columns:
Customer, ProductCode, Value
I can get Value for each product for the customer, and the total value for the customer to appear in one result row:
select
Customer
,ProductCode
,Value
,sum(Value) over (partition by Customer) as TotValForCust
from
Sales
I am having trouble ranking the customers by total sales.
I Require:
Customer, ProductCode, Value, TotValForCust, RankbyTot
I cannot get the syntax correct - each variation I use throws out errors such as missing Group By etc.
I need something like
select
Customer
,ProductCode
,Value
,sum(Value) over (partition by Customer) as TotValForCust
,rank() over (order by sum(Value) over (partition by Customer) as RankbyTot
from
Sales
Any ideas?
Consider a table with three columns:
Customer, ProductCode, Value
I can get Value for each product for the customer, and the total value for the customer to appear in one result row:
select
Customer
,ProductCode
,Value
,sum(Value) over (partition by Customer) as TotValForCust
from
Sales
I am having trouble ranking the customers by total sales.
I Require:
Customer, ProductCode, Value, TotValForCust, RankbyTot
I cannot get the syntax correct - each variation I use throws out errors such as missing Group By etc.
I need something like
select
Customer
,ProductCode
,Value
,sum(Value) over (partition by Customer) as TotValForCust
,rank() over (order by sum(Value) over (partition by Customer) as RankbyTot
from
Sales
Any ideas?