如何解决带有数据的where子句的SQL查询
TranID HotelID FacilityID
7 1 4
9 1 8
12 2 4
13 2 8
19 9 4
229 2 8
244 74 8
我希望像这样显示,其中酒店ID对于不同的FacilityID
是相同的TranID HotelID FacilityID
7 1 4
9 1 8
12 2 4
13 2 8
所以请提前帮助我
答案 0 :(得分:1)
检查一下:
SELECT t1.*
FROM tableHotel t1
WHERE EXISTS
(
SELECT 1 FROM tableHotel t2
WHERE t2.HotelID= t1.HotelID
AND t2.FacilityID <> t1.FacilityID
)
答案 1 :(得分:0)
Select * from [My-table]
where HotelID in (1, 2)
答案 2 :(得分:0)
SELECT * FROM [YourTable]
WHERE TranID IN (7,9,12,13)
答案 3 :(得分:0)
SELECT * from table where HotelID IN (1,2)
答案 4 :(得分:0)
SELECT DISTINCT h.*,c.CITY
FROM MST_FacilityTrans t1
INNER JOIN MST_HOTEL h on h.HotelID=t1.HotelID
INNER JOIN MST_City c on h.CityID=c.CityID
WHERE EXISTS
(
SELECT 1 FROM MST_FacilityTrans t2
WHERE t2.HotelID= t1.HotelID
AND t2.FacilityID <> t1.FacilityID
)