解析在一個SQL語句中同時出現count()、where、group by 的先後執行順序

如:select count(*) from tab1 where publi_id='1000000141' and cent_id='3702000001'

它是先根據條件利用where查詢出所有數據,然後利用count將每條數據彙總,就是算一下有多少條數據

如:select count(*) from tab1 where publi_id='1000000141' and cent_id='3702000001'   group by  comp_id

它是先根據where條件查詢出所有的數據,然後按照group by 來對comp_id進行分組,分完組後count會對每組的每條數據進行彙總

(注意:group by 後,count是對每組中的數據進行彙總)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章