where、having、group by、order by、count的使用注意
生活随笔
收集整理的這篇文章主要介紹了
where、having、group by、order by、count的使用注意
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
where、having、group by、order by、count的使用注意
- 1_where、having、group by、order by的順序
- 2_group by的作用
- 3_where和group by的組合
- 4_group by和having的組合
- 5_where、having、group by的組合使用
- 6_count與group by的組合使用
1_where、having、group by、order by的順序
where、 group by、 having、 order by
2_group by的作用
注意事項:分組后只能對分組屬性進(jìn)行操作
錯誤舉例:select name from table_name group by type
由于group by type ,所以分組屬性是type,不能select name
3_where和group by的組合
先where進(jìn)行按單個元組進(jìn)行條件篩選,后通過group by對篩選后的集合進(jìn)行分組
--選擇庫存編號大于10000并按種類分組 select type from repertory_record where repertory_id > 10000 group by type4_group by和having的組合
先where進(jìn)行按單個元組進(jìn)行條件篩選,再使用group by 進(jìn)行分組 ,最后使用having對分組后的一個個集合進(jìn)行操作
--先按照種類進(jìn)行分組,再從這些組中挑選'杯子','電腦','耳機(jī)'這三類 select type from repertory_record group by type having type in ('杯子','電腦','耳機(jī)')5_where、having、group by的組合使用
使用group by進(jìn)行分組,再使用having對分組后的一個個集合進(jìn)行操作
--先使用where篩選編號大于10000的記錄,再使用group by進(jìn)行按種類分組,最后使用having在已經(jīng)分好組的集合中選擇種類不是'杯子','電腦','耳機(jī)'這三類的記錄 select type from repertory_record where repertory_id > 1000 group by type having type not in ('杯子','電腦','耳機(jī)')6_count與group by的組合使用
--如上圖所示為分組后的狀態(tài),分組后統(tǒng)計每個組的元組數(shù)目count(type) select type,count(type) from repertory_record where repertory_id < 10004 group by type總結(jié)
以上是生活随笔為你收集整理的where、having、group by、order by、count的使用注意的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win10专业版系统PyCharm专业版
- 下一篇: Tensorflow No modul