I have 3 tables as described below
MonthlyOrder table 4 columns
CustomerID
DateID (represented in integer and as the first of the month = 20121201)
OrderCount – INT
HoursSpend Tbale has 4 columns
CustomerID
DateID
Function – VARCHAR() — Functions are Reporting, Admini and Sales calls
Hours – INTEGER — Hours spent on each function during the month
Rates Table has 3 columns
CustomerID
AccountRate — Money (IF NULL then default is $50)
OperationRates – Money
The calculation that I need to achieve from this tables are
(LoadCount*AccountRate) + ((Hours for Reporting Function from HoursSpend table + Hours for Amin + Hours for Sales calls) * OperationRates from Rates table)
Please advise on the best way to achieve this calculation
MonthlyOrder
CustomerID DateID OrderCount
1 20121201 20
1 20121202 10
2 20121210 100
HoursSpend
CustomerID DateID Function Hours
1 20121201 Reporting 2
1 20121201 Admin 3
1 20121201 Sales Calls 5
1 20121201 Training 10
Rates
CustomerID AccountRate OperationRates
1 $18 $50
CALCULATION – > (OrderCount*AccountRate) + ((Reporting Hours + Admin Hours + Sales Calls Hours) * OperationRates)
EXAMPLE for customerID 1 on 20121201 -> (20*18) + ((2+3+5) * 50) = $860
** Notice that the Hours for Training are not included as the only hours that I care about is Reporting + Admin + Sales Calls
Assuming that following column combinations are unique: MonthlyOrder[CustomerID,DateID], HoursSpend[CustomerID,DateID,Function], Rates[CustomerID]
you could use something like: