我有以下两个表:
1. BList
- 预订ID
- 成人没有
- 孩子没有
- 预定日期
2. B手柄
- 预订ID
- 票务状态
- 最终售价
- 终网
- 职员
我想要做的是获得distinct Staff
with Sum of (SellingPrice)
, Sum of (NettPrice)
, Profit (Sum of sellingPrice)- Sum of (NettPrice))
, No of Pax 这是(AdultNo + ChildNo)
并且也算作BookingID
No of Bookings
WHERE BookingDate >= fromDate AND BookingDate <= toDate
AND TicketingStatus='CP'
看起来像这样的东西(底部的总数无关紧要,因为我会将它们写入 csv 格式,我将在那里处理总数)但我需要先弄清楚如何获取查询。
这是我可以从第二个表BHandle获得的查询
SELECT Staff, SUM(FinalSellingPrice) AS gross, SUM(FinalNett) AS cost
FROM BHandle
WHERE ticketingstatus ='CP'
GROUP BY Staff
这是我对第一个表BList的查询
SELECT (adultno+childno) AS pax
fFROM om BList
WHERE bookingdate >='01-mar-2013 00:00'
AND bookingdate <= '15-may-2013 23:59'
如何将这两个查询组合在一起?