2017-02-09 8 views
0

私はSQLを初めて使用しているので、ここで検索してもウェブ上でも私の問題を把握することはできませんでした。私はテーブルや机のような製品を選択する必要があり、その価格は300ドル以上で、他のものはすべて正しかったですが、私は300ドル以上のものではなく、すべてのドル額を返しています。SQL LIKE句が適切な桁を返さない

SELECT ProductDescription, ProductFinish, ProductStandardPrice 
FROM product_t WHERE ProductDescription LIKE '%table%' 
OR (ProductDescription LIKE '%desk%' AND ProductStandardPrice > 300); 

製品説明は、「表」が含まれている場合、それは関係なく、返されます。ここで

は声明

SELECT ProductDescription, ProductFinish, ProductStandardPrice 
FROM product_t WHERE ProductDescription LIKE '%table%' OR ProductDescription LIKE '%desk%' 
AND ProductStandardPrice > 300; 
+0

'(ProductDescription LIKE '%テーブル%' OR ProductDescription LIKE '%デスク%') とProductStandardPriceを> 300' –

+0

あなたは上または中カッコが欠落していますペア –

答えて

1

operator precedenceがあなたのクエリは次のように解釈されることを意味、あなたの書式にもかかわらずです価格。常に価格を確認するには、単に適切に括弧を挿入します。

SELECT ProductDescription, ProductFinish, ProductStandardPrice 
FROM product_t WHERE (ProductDescription LIKE '%table%' OR ProductDescription LIKE '%desk%') 
AND ProductStandardPrice > 300; 
+0

ありがとう、私は説明を感謝します! –

+0

@ l.bolこれで問題が解決した場合は、[同意してください](http://meta.stackexchange.com/q/5234/304954) – shmosel

関連する問題