如何使用"喜欢"用"和"在SQL?

时间:2014-12-17 06:02:22

标签: sql

我想选择“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

3 个答案:

答案 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)

您需要使用ORAND

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%'