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;
原文地址:http://1154179272.blog.51cto.com/10217799/1653235