我的where子句与我想要的相反

时间:2016-07-19 19:33:21

标签: mysql where where-clause

这是我的查询。

select sp.name, spi.sku, sum(spi.price), count(sp.name), spi.in_stock, spi.price, sp.is_published, spi.is_reorderable
from shop_product_category spc
inner join shop_product_category_xref spcx
on spc.shop_product_category_id = spcx.shop_product_category_id
inner join shop_product sp
on sp.shop_product_id = spcx.shop_product_id
inner join shop_product_item spi
on spi.shop_product_id = sp.shop_product_id
inner join shop_order_item soi
on spi.shop_product_item_id = soi.shop_product_item_id
where (spc.shop_product_category_id in (1316))
 and sp.is_published = 1
group by sp.name
order by count(sp.name) desc

它返回一切就好了除了我希望它返回sp.is_published = 1的行因此where子句。然而,要获得所需的输出,我必须将当前的where子句更改为     sp.is_published <> 1 所以问题是这个,为什么&lt;&gt; 1返回带有1的行,= 1返回带有0的行。谢谢

1 个答案:

答案 0 :(得分:0)

如果sp.is_published = 1是一个字符串,那么您需要将其放入标记IE sp.is_published = '1'