嘿,我正在使用oracle sql来创建数据库.
我现在正在处理查询,我想出了两个单独的quires,我想合并以获得结果.
我创建的第一个查询是查找演出所产生的总金额:
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)
Run Code Online (Sandbox Code Playgroud)
这给了我一个结果:
337.5
Run Code Online (Sandbox Code Playgroud)
然后我有另一个查询,计算出总的特许金:
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 …Run Code Online (Sandbox Code Playgroud) 我已经计算了不同表中的计数总和.这样做两次,每次一次performanceID.现在我想得到两笔钱的总和.
下面是我现在做的两笔钱的代码:
SELECT SUM((COUNT (BookingID) * CategoryPrice)) AS TotalAmount
FROM Booking, Production
WHERE Booking.PerformanceID IN(SELECT PerformanceID FROM Performance WHERE PerformanceID = '1')
and Production.ProductionID IN
(SELECT ProductionID FROM Performance WHERE PerformanceID = '1')
GROUP BY BookingID, CategoryPrice
UNION ALL
SELECT SUM((COUNT (BookingID) * CategoryPrice)) AS TotalAmount
FROM Booking, Production
WHERE Booking.PerformanceID IN(SELECT PerformanceID FROM Performance WHERE PerformanceID = '2')
and Production.ProductionID IN
(SELECT ProductionID FROM Performance WHERE PerformanceID = '2')
GROUP BY BookingID, CategoryPrice
Run Code Online (Sandbox Code Playgroud)
我得到的结果是:
TOTALAMOUNT
-----------
70 …