复杂的多维数据集查询

时间:2014-04-23 21:54:03

标签: oracle

我正在研究一个相当复杂的视图,它根据从四个不同表格中提取的数据计算客人住宿的总费用。然而输出并不是我想要的。我的代码是

   CREATE OR REPLACE VIEW Price AS
   SELECT UNIQUE
   Booking.Booking_ID AS "Booking", 
   Booking.GuestID AS "Guest ID",
   Room.Room_Price*(Booking.CheckOutDate-Booking.CheckInDate) AS "Room Price",
   Add_Ons.Price AS "Add ons Price",
   Room.Room_Price*(Booking.CheckOutDate-Booking.CheckInDate) + (Add_Ons.Price) AS "Total Price"
   FROM Booking  JOIN Room ON Room.Room_Num = Booking.Room_Num
                 JOIN Booking_Add_Ons ON Booking.Booking_ID = Booking_Add_Ons.Booking_ID
                 JOIN Add_ons ON Booking_Add_Ons.Add_On_ID = Add_Ons.Add_On_ID
   ORDER BY Booking.Booking_ID;

现在,我正在努力让这个回报所有插件的总费用,加上酒店房间的总价格作为总价格,但它会将房间的成本+每个插件的成本返回到单独的线路上。如下:

Command prompt return of the price view

我的问题是,是否可以使用类似CUBE或SUM的内容来添加行,这样每个预订只有一个条目,所有附加组件的总价格占了?

0 个答案:

没有答案