我想查询所有手工制作的圣诞节,但我得到所有的圣诞节价值。
SELECT * FROM PRODUCT WHERE PROD_CAT = 'Christmas' OR SEC_CAT = 'Christmas'
AND SUB_CAT = 'Handmade' OR SEC_SUB_CAT = 'Handmade'
如何从圣诞节获得所有手工制作?
答案 0 :(得分:1)
你只需要放括号,然后就可以了:
SELECT * FROM PRODUCT WHERE (PROD_CAT = 'Christmas' OR SEC_CAT = 'Christmas')
AND (SUB_CAT = 'Handmade' OR SEC_SUB_CAT = 'Handmade');
如有任何疑问,请与我联系。
答案 1 :(得分:0)
使用括号。我认为你想要:
SELECT *
FROM PRODUCT
WHERE (PROD_CAT = 'Christmas' OR SEC_CAT = 'Christmas') AND
(SUB_CAT = 'Handmade' OR SEC_SUB_CAT = 'Handmade');
答案 2 :(得分:0)
您必须使用括号使sql清楚地显示您想要的内容
SELECT * FROM PRODUCT WHERE (PROD_CAT = 'Christmas' OR SEC_CAT = 'Christmas')
AND (SUB_CAT = 'Handmade' OR SEC_SUB_CAT = 'Handmade')
答案 3 :(得分:0)
在某些版本的SQL上,我们可以进一步简化您的查询:
SELECT *
FROM PRODUCT
WHERE 'Christmas' IN (PROD_CAT, SEC_CAT) OR 'Handmade' IN (SUB_CAT, SEC_SUB_CAT);