I have two tables like below
Book
id TID reserveddate fee1 fee2 fee3 Noofplayers total
-------------------------------------
1 11 2012-11-25 100 200 300 3 800
2 12 2012-11-25 100 200 300 3 800
3 13 2012-11-28 200 100 200 1 500
Players
TID fee1 fee2
-------------------------------------
11 100 200
11 100 200
11 100 200
12 100 200
12 100 200
12 100 200
13 200 100
now i would like to retrieve data from both tables with group by Reserveddate.
I have a query,
select sum(b.fee1)+sum(b.fee2)+sum(a.fee3) as total
from Players b,book a where a.TID = b.TID and a.ReservedDate ='25-nov-2012'
group by a.ReservedDate
the above query in sum(fee3) adding 3(noofplayers) times i want to add one time book table.
could you please update the query as per client requirement…
I believe this would work, it would give total of 2400:
Here is how the total is getting calculated:
For TID=11: 300 (sum of Players.fee1) + 600 (sum of Players.fee2) = 900
For TID=12: 300 (sum of Players.fee1) + 600 (sum of Players.fee2) = 900
900 + 900 = 1800
1800 + 600 (sum of Book.fee3 for date ‘2012-11-25’) = 2400
Here is an example: SQL Fiddle