在加入、工会、ON-s 等方面,我不是很有经验,但我有一所学校,我需要从两张表中选择客户名称,贵宾和普通客户。
我尝试了两种方法,但不幸的是没有任何效果://1
SELECT Hotel_Rooms.Book_From, Hotel_Rooms.Book_To, Hotel_Rooms.[Book_To]-[Book_From] AS Booked_Days, Hotel_Rooms.[Price_Per_Night]*[Booked_Days] AS Price, Reg_Customers.Cust_name
FROM Reg_Customers
UNION
SELECT Hotel_Rooms.Book_From, Hotel_Rooms.Book_To, Hotel_Rooms.[Book_To]-[Book_From] AS Booked_Days, Hotel_Rooms.[Price_Per_Night]*[Booked_Days] AS Price, Vip_Customers.Cust_name
FROM Vip_Customers
INNER JOIN Hotel_Rooms ON Reg_Customers.Cust_ID = Hotel_Rooms.Cust_ID && Vip_Customers.Cust_ID = Hotel_Rooms.Cust_ID
ORDER BY Hotel_Rooms.[Price_Per_Night]*[Booked_Days] DESC;
//2
SELECT Hotel_Rooms.Book_From, Hotel_Rooms.Book_To, Hotel_Rooms.[Book_To]-[Book_From] AS Booked_Days, Hotel_Rooms.[Price_Per_Night]*[Booked_Days] AS Price, Reg_Customers.Cust_name, Vip_Customers.Cust_name
FROM Reg_Customers, Vip_Customers
INNER JOIN Hotel_Rooms ON Reg_Customers.Cust_ID = Hotel_Rooms.Cust_ID && Vip_Customers.Cust_ID = Hotel_Rooms.Cust_ID
ORDER BY Hotel_Rooms.[Price_Per_Night]*[Booked_Days] DESC;
没有一个查询可以正确选择、连接表。你能帮忙吗?表格方案,如果这些有帮助
房间 { Rooms_ID, Cust_ID, Room_Capacity, Available, Book_Time, Book_Price_Per_Night, Book_From, Book_To }
普通客户 {Cust_ID, Cust_Name, Cust_Phone, Cust Card} vip {Cust_ID, Cust_Name, Cust_Phone, Cust Card}
谢谢你。如果您可以提供一个有效的查询,无论是#1 还是#2 版本,那就太好了,谢谢。