我正在尝试实施查询以找到西班牙最便宜的套餐。
我的'Where h.location ='西班牙'有问题。我需要where函数来方便我的其他列。例如: - e.location,t.location和f.location。这将全部='西班牙'
SELECT p.*, (h.totalCost + e.totalCost + t.totalCost + f.totalCost) as 'Total Package Cost' FROM Package p
INNER JOIN hotels h ON h.hotelId = p.hotelId
INNER JOIN excursions e ON e.excursionId = p.excursionId
INNER JOIN transport t ON t.transportId = p.transportId
INNER JOIN flight f ON f.flightId = p.flightId
WHERE h.location = 'Spain'
ORDER BY (h.totalCost + e.totalCost + t.totalCost + f.totalCost) ASC
如何解决这个问题?
答案 0 :(得分:2)
如果他们都必须等于"西班牙"然后只需使用AND
将它们添加到WHERE子句中 WHERE h.location = 'Spain'
AND e.location = 'Spain'
AND t.location = 'Spain'
AND f.location = 'Spain'
答案 1 :(得分:2)
我建议这样做
WHERE h.location = 'Spain'
AND e.location = h.location
AND t.location = h.location
AND f.location = h.location
所以,如果你想改变"西班牙"的变量。 (我假设它将是一个变量),您只需要在查询中包含一个位置。