我想选择“XBox 360”和“XBox One”这两种格式。但查询仅选择“XBox 360”格式。
这是我的SQL查询。
select id,name,rate_score,rate_number,video_image from products where release_on >= '$bef1mo' and (formats like '%XBox 360%' and formats like '%XBox One%') order by id desc limit 0,4
答案 0 :(得分:1)
使用or
代替and
,如下面的代码。
select id,name,rate_score,rate_number,video_image from products where release_on >= '$bef1mo' and (formats like '%XBox 360%' or formats like '%XBox One%') order by id desc limit 0,4
答案 1 :(得分:0)
我想您想在or
(formats like '%XBox 360%' and formats like '%XBox One%'
select id,name,rate_score,rate_number,video_image from products where
release_on >= '$bef1mo' and
(formats like '%XBox 360%' OR formats like '%XBox One%')
order by id desc limit 0,4
因为逻辑和均值必须匹配(不是)。
答案 2 :(得分:0)
您需要使用OR
非AND
select id,name,rate_score,rate_number,video_image
from products
where release_on >= '$bef1mo'
and (formats like '%XBox 360%'
OR formats like '%XBox One%')
order by id desc limit 0,4
AND:选择BOTH Formats ='%XBox 360%'和Formats ='%XBox One%'
或者:选择Where Formats'%XBox 360%'或格式='%XBox One%'