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)
浙公网安备 33010602011771号