2019-02-18
阅读量:
1227
SQL中如何将空值转换为int类型
问题描述:
MySQL库存(store)字段为null,判断了库存导致SQL无法查询结果?
$sql = "SELECT a.image_default_id,b.product_id,b.price,b.mktprice,b.name FROM `sdb_b2c_goods` AS a
INNER JOIN sdb_b2c_products AS b ON a.goods_id=b.goods_id
WHERE a.marketable='true'
AND a.verify='1'
AND a.disabled='false'
AND b.disabled='false'
AND b.store>b.freez
AND (b.store-b.freez)>0
AND b.product_id IN ($productId)
ORDER BY FIELD(product_id,{$productId})";
如何将store为null的时候 强制转换为int类型呢?
解决方法:
IFNULL(store, 0);






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论