在SQL中,我编写了这两个查询:
查询1:
SELECT HotelID, HotelName, Email FROM Hotel
WHERE HotelID IN (SELECT Branch.HotelID FROM Branch
WHERE BranchAddress LIKE '%London%');
查询2:
SELECT Branch.HotelID, COUNT(*)
FROM Branch
GROUP BY HotelID
HAVING COUNT(*) > 5;
我希望将这两个查询组合在一起,以便生成的结果基于这两个中的任何一个。
我将如何做到这一点?我认为联合可以使用,但不确定这是否是正确的使用方法。
答案 0 :(得分:0)
SELECT a.hotelid,
a.hotelname,
a.email,
Count(*)
FROM hotel a
JOIN branch b
ON a.hotelid = b.hotelid
WHERE b.branchaddress LIKE '%London%'
GROUP BY a.hotelid,
a.hotelname,
a.email
HAVING Count(*) > 5