介于两者之间不适用于多个AND - MYSQL

时间:2017-07-06 17:26:46

标签: mysql between

SELECT price from items Where categoryId = 11724 AND price BETWEEN 10 AND 20

结果:

17.99 {
{1}} {
{1}} {
{1}} {
{1}}

以上查询工作正常,但添加另一个子句不会显示所需的结果

18.95
  

结果:找到0行

20.0

结果:
价格
17.99 {
{1}} {
{1}} {
{1}} {
{1}}

为每个条款尝试了18.95SELECT price from items Where categoryId = 11724 AND ( brand = 'Akaso' OR brand = 'Andoer') and price BETWEEN 10 AND 20 类型为SELECT price from items Where categoryId = 11724 AND brand = 'Akaso' OR brand = 'Andoer' and price BETWEEN 10 AND 20
17.99 我在哪里做错了?

2 个答案:

答案 0 :(得分:1)

我没有您的数据,但我觉得一切正常,您的上一次查询正在尝试这样做:

SELECT price from items
Where (categoryId = 11724
AND brand = 'Akaso') OR (brand = 'Andoer'
and price BETWEEN 10 AND 20)

答案 1 :(得分:0)

感谢大家的回复。将VARCHAR类型更改为Decimal后,这对我有用:

SELECT price,categoryId,brand from items 
Where categoryId = 11724 
and (brand = 'Akaso' OR brand = 'Andoer') 
and (price BETWEEN 40 AND 50)

SELECT price,categoryId,brand from items 
Where (categoryId = 11724)
and (brand = 'Akaso' OR brand = 'Andoer') 
and (price BETWEEN 40 AND 50)

SELECT price,categoryId,brand from items 
Where categoryId = 11724 
and (brand = 'Akaso' OR brand = 'Andoer') 
and price BETWEEN 40 AND 50 

下面没有用:

SELECT price,categoryId,brand from items 
Where categoryId = 11724 
and brand = 'Akaso' OR brand = 'Andoer' 
and (price BETWEEN 40 AND 50)

很想知道第3次和第4次查询之间的区别。