查询本店比市场价便宜200的商品
where写法的缺点是 market_price-shop_price
算了两遍
// where写法
select goods_id,goods_name,market_price-shop_price from goods
where (market_price-shop_price)>200
定义变量的写法会报错,因为 where 是针对原始表里的列触发的
// 将`market_price-shop_price` 取变量 `is_cheap`
select goods_id,goods_name,(market_price-shop_price) as is_cheap from goods
where is_cheap>200
// 报错:unknow column 'is_cheap' in 'where clause'
用 having,having 一定写在 where 后面
select goods_id,goods_name,(market_price-shop_price) as is_cheap from goods
having is_cheap>200