Sql错误1064,语法错误

时间:2016-03-11 17:39:36

标签: mysql sql

我有一个SQL查询

Select * from `products`
where (`product_company`='mad over donuts' OR
       `product_company`= 'dunkin donuts')
AND (`flavour`='vanilla')
AND (355 < `price` < 561 ) ;

它提取的元素大于某个固定价格且低于某个固定价格。它还包括其他约束。但是当我运行这个SQL查询时它给了我一个

  
    

1064 - 您的SQL语法出错;检查与您的MySQL服务器版本相对应的手册,以便在'products附近使用正确的语法(product_company ='疯狂的甜甜圈'或'产品'在第1行。

  

我检查了我的sql语法,我似乎没有遇到问题。有人,拜托?

3 个答案:

答案 0 :(得分:3)

代替这个

Select * from `products`
where (`product_company`='mad over donuts' OR
       `product_company`= 'dunkin donuts')
AND (`flavour`='vanilla')
AND (355 < `price` < 561 )";

“导致问题

试试这个

Select * from `products`
where (`product_company`='mad over donuts' OR
       `product_company`= 'dunkin donuts')
AND (`flavour`='vanilla')
AND (`price`BETWEEN 355 and 561 );

答案 1 :(得分:2)

更改

355 < price < 561) 

price between 356 and 560

纠正问题(包括等于之间需要缩小范围)

Select * from `products`
    where (`product_company`='mad over donuts' OR
           `product_company`= 'dunkin donuts')
    AND (`flavour`='vanilla')
    AND price between 355 and 561

答案 2 :(得分:0)

使用BETWEEN

Select * from `products`
where (`product_company`='mad over donuts' OR
       `product_company`= 'dunkin donuts')
AND (`flavour`='vanilla')
AND (`price` between 355 and 561 )" ;