码迷,mamicode.com
首页 > 其他好文 > 详细

9_查询之having

时间:2015-05-20 18:48:07      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:having   市场价格   where   sheng   

select 5种子句:
	where 条件查询
	group by 分组
	having 筛选
	order by 排序
	limit 限制结果条数

---------------------

having

where是对表起作用,
而having是对已查询出来的结果进行筛选

查询出本店商品价格比市场价格小200的商品:
select goods_name,market_price - shop_price as sheng from goods having sheng>200;


查询出本店中栏目为3的商品价格比市场价格小200的商品:
select cat_id,goods_name,market_price -shop_price as sheng from goods where cat_id=3 having sheng>200;


查询积压货款超过2w的栏目,以及该栏目积压的货款
select cat_id,sum(shop_price * goods_number) as hk from goods group by cat_id having hk>20000;


9_查询之having

标签:having   市场价格   where   sheng   

原文地址:http://1154179272.blog.51cto.com/10217799/1653235

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!