Hi, I am using oracle sql to create a database.
Now I am working on queries, and I have two separate queries that I would like to combine to get the result.
The first query I created is to find out the total amount of money produced by the performance:
SELECT SUM(bookings * CategoryPrice )AS Total_Money_Made
FROM ( SELECT CategoryPrice , count(*) AS bookings
FROM Booking b
JOIN performance per
ON b.performanceid = per.performanceid
JOIN Production p
ON per.productionid = p.productionid
WHERE per.performanceid IN (1, 2, 3, 4)
GROUP BY CategoryPrice)
This gives me the result:
TOTAL_MONEY_MADE
337.5
Then I have another request that returns the total amount of concession money:
SELECT SUM(ConsessionAmount * 2) AS Total_Consession_Money
FROM( SELECT COUNT (*) AS ConsessionAmount
FROM Booking
WHERE
Consession = 'Yes' AND PerformanceID = '1' OR
Consession = 'Yes' AND PerformanceID = '2' OR
Consession = 'Yes' AND PerformanceID = '3' OR
Consession = 'Yes' AND PerformanceID = '4' )
This gives me the result:
TOTAL_CONSESSION_MONEY
18
Now I want me to be able to subtract the result from the second query from the first query. Is it possible? and how can i do this? I think this has something to do with subqueries, but I'm not sure.
Any help? Thank.
source
share