where和having的区别
1、用的地方不一樣
where可以用在select ?update delete insert......into語句中
having只能用在select語句中
2、執行順序不一樣
where的搜索條件是在執行語句進行分組之前應用
having的搜索條件是在分組條件之后執行的
如果where和having同事出現在語句中時 也會先執行where后執行having
3.子句有區別?
where子句中的條件表達式having都可以跟,而having子句中的有些表達式where不可以跟;having子句可以用集合函數(sum、count、avg、max和min),而where子句不可以。?有些地方兩者都可以用,比如?
having:select?studentid,?avg(score)?from?studentScore??group?by?studentid?having?left(studentid,?1)='0'?
where:select?studentid,?avg(score)?from?studentScore?where?left(studentid,?1)='0'?group?by?studentid?
這種情況下哪個會快一點??解析:?
select?studentid,?avg(score)?from?studentScore?group?by?studentid?having?left(studentid,?1)='0'??
1、分組匯總?2、過濾非法項?
left(studentid,?1)='0'是個效率不很高的過濾條件,如果分組會使數據量極大減少(比如每個人有幾十門課),而且要過濾掉的只是很小一部分學生,這種寫法會有比較高的效率?
 wk_ad_begin({pid : 21});wk_ad_after(21, function(){$('.ad-hidden').hide();}, function(){$('.ad-hidden').show();}); if( navigator.userAgent.indexOf("MSIE 6.0") < 0 ){BAIDU_CLB_fillSlot( '920314' );} 
?
select?studentid,?avg(score)?from?studentScore?where?left(studentid,?1)='0'?group?by?studentid??
1、過濾非法項?2、分組匯總?
雖然left(studentid,?1)='0'是個效率不很高的過濾條件,但是如果你要從幾百萬學生中找到幾十個學生3-5門功課的平均分,還是應該很明智的選擇它
轉載于:https://www.cnblogs.com/xiaoping-2014/p/4081532.html
總結
以上是生活随笔為你收集整理的where和having的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 转:PHP非阻塞模式
- 下一篇: Oracle RAC集群体系结构
