Click here to Skip to main content
16,016,067 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi everyone,

I´m stuck on a SQL statement which contains the following calculation:

I have three tables in my database foto
1.rates (rate_id, price, frequency),2.rate_changes (old_rate_id, new_rate_id, photographer_id) and payments (created, amount_net)

Further, I want to calculate the amount_net per month depending on the rate frequency but I dn´t know exactly how to do it:

SQL
SELECT sum(
if foto.rates.frequency = 1 then (sum foto.payments.amount_net(month x))
elseif foto.rates.frequency = 3 then (foto.payments.amount_net (month x)/foto.rates.frequency) And foto.payments.amount_net (month x-2)+foto.payments.amount_net (month x)/foto.rates.frequency, foto.payments.amount_net (month x-1) + foto.payments.amount_net (month x)/foto.rates.frequency

elseif foto.rates.frequency = 6 then..(the same calculation as in the case before)
elseif foto.rates.frequency = 12 then..(the same calculation as in the cases before))

End


Thanks a lot in advance for your help!
Posted
Comments
Maciej Los 11-Apr-14 6:37am    
Use "Improve question" widget to post sample data.

1 solution

Hello,

How about trying to use a function? That would be helpful in the result you want to achieve.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900