Hi,
I am trying to get an average percentage for child discounts on hotels. I'll describe what i go so far. I have a table with:
ID | Contract_id | from_age | to_age | discount |
1 | 15 | 0 | 6 | 100 |
2 | 15 | 7 | 12 | 50 |
My example that i am running is for 3 children on a booking:
1st child : 3 years old
2nd child: 4 years old
3rd child: 9 years old
So according to the table the 1st child has 100% discount so as the second, the third child with 9 years old has 50% , summing all discounts per each child should be a total of 250% , now to calculate the average i divide by the number of children wich the average percent is now: 83.33% .
Now my problem is to put this on mysql query without using server side code such as php. this is what i got so far.
SELECT sum(discount) as average FROM reductions WHERE from_age<=9 and to_age>=2
When i perform this it gives the total percentage of 150% instead of 250%
can anyone help me with this?
thanks