首页 > 代码库 > having和where的区别
having和where的区别
区别:
where:语句条件字段,必须是“数据表中存在的”字段
having:语句条件字段 必须是查询结果集中存在的字段
having()设置sql语句查询条件
group by 就使用having
where 和 having都可以设置查询条件,两种在某些场合可以通用
where:条件字段必须是“数据表” 存在字段
having:条件字段必须是“结果集”中的字段
一、两者可以通用
select * from goods where goods_price > 1000; select * from goods where goods_price >1000;
二、只能用where (不能用having)
select goods_id,goods_name from goods where goods_price > 1000; select goods_id,goods_name from goods having goods_price > 1000;//错误,因为结果集中没有goods_price
三、只能用having(不能用where)
select goods_brand_id,count(*) as cnt from goods having cnt > 3; selecct goods_brand_id,count(*) as cnt from goods where cnt > 3;//错误,因为表中没有cnt
having和where的区别
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。