有没有办法简化这个WHERE语句,所以只需要声明一次Airport和StoreName,让类别和夹具变化?
SELECT * FROM Product_Display
WHERE (Airport = 'JFK' AND StoreName = 'T3' AND Category = 'Pralines' AND FIXTURE like '%W15%')
OR (Airport = 'JFK' AND StoreName = 'T3' AND Category = 'Kinder' AND FIXTURE like '%W12%')
OR (Airport = 'JFK' AND StoreName = 'T3' AND Category = 'Nutella' AND FIXTURE like '%G04%')
OR (Airport = 'JFK' AND StoreName = 'T3' AND Category = 'Tic Tac' AND FIXTURE like '%W12%')
答案 0 :(得分:3)
您可以简化如下
SELECT * FROM Product_Display
WHERE Airport = 'JFK' AND StoreName = 'T3' AND ((Category = 'Pralines' AND FIXTURE like '%W15%')
OR (Category = 'Kinder' AND FIXTURE like '%W12%')
OR (Category = 'Nutella' AND FIXTURE like '%G04%')
OR (Category = 'Tic Tac' AND FIXTURE like '%W12%'))
希望这会帮助你。
答案 1 :(得分:2)
SELECT *
FROM Product_Display
WHERE Airport = 'JFK'
AND StoreName = 'T3'
AND ( ( Category = 'Pralines' AND FIXTURE LIKE '%W15%' )
OR ( Category = 'Kinder' AND FIXTURE LIKE '%W12%' )
OR ( Category = 'Nutella' AND FIXTURE LIKE '%G04%' )
OR ( Category = 'Tic Tac' AND FIXTURE LIKE '%W12%' )
)
答案 2 :(得分:2)
以下查询在语义上相同,但可能更容易阅读:
SELECT * FROM Product_Display
WHERE (Airport = 'JFK' AND StoreName = 'T3') AND
( (Category = 'Pralines' AND FIXTURE like '%W15%')
OR (Category = 'Kinder' AND FIXTURE like '%W12%')
OR (Category = 'Nutella' AND FIXTURE like '%G04%')
OR (Category = 'Tic Tac' AND FIXTURE like '%W12%')
)
答案 3 :(得分:1)
只需将机场和商店名称放在括号内,如下所示:
SELECT * FROM Product_Display
WHERE Airport = 'JFK' AND StoreName = 'T3' AND
(
(Category = 'Pralines' AND FIXTURE like '%W15%')
OR (Category = 'Kinder' AND FIXTURE like '%W12%')
OR (Category = 'Nutella' AND FIXTURE like '%G04%')
OR (Category = 'Tic Tac' AND FIXTURE like '%W12%')
)