where & having

where 和 having 都是那啥。。

区别:

1.where先执行,having后执行

2.where后面的列名称必须是数据库表中的列的名称,但是having后面的列的名称是一个查询语句select出的列的名称或者别名或者聚合函数结果的别名。

 

select  usrname,usrid,passwd from user where usrid > 10;

select usrname,usrid,passwd from user having usrid >10;

 

select usrname,password from user where usrid > 10; (right)

select usrname,password from user having usrid >10;(wrong);

 

select categoryid,avg(price) as avg_price from goods group by categoryid  having avg_price >100;(right)

select categoryid,avg(price) as avg_price from goods where avg_price >100 group by categoryid;(wrong)

posted on 2017-03-26 21:55  blbl9527  阅读(69)  评论(0)    收藏  举报

导航


github sina微博 FB