2017-02-09 4 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

'WHERE (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

관련 문제