I have the following two tables:
1. BList
- BookingID
- AdultNo
- ChildNo
- BookingDate
2. BHandle
- BookingID
- TicketingStatus
- FinalSellingPrice
- FinalNett
- Staff
What I want to do is get the distinct Staff
with Sum of (SellingPrice)
, Sum of (NettPrice)
, Profit (Sum of sellingPrice)- Sum of (NettPrice))
, No of Pax which is (AdultNo + ChildNo)
and also count the BookingID
as No of Bookings
WHERE BookingDate >= fromDate AND BookingDate <= toDate
AND TicketingStatus='CP'
Something that looks like this (The Total figures at the bottom doesn't matter as i will write them to csv format, i will handle the total there) but i need to figure out how to get the query first.
This is the query i can get from the 2nd Table BHandle
SELECT Staff, SUM(FinalSellingPrice) AS gross, SUM(FinalNett) AS cost
FROM BHandle
WHERE ticketingstatus ='CP'
GROUP BY Staff
This is my query for the 1st table BList
SELECT (adultno+childno) AS pax
fFROM om BList
WHERE bookingdate >='01-mar-2013 00:00'
AND bookingdate <= '15-may-2013 23:59'
How can I combine these 2 queries together?
One way to do this is using
union all
with an aggregation:Something like this (assuming all columns are non null):