數據庫統計不同字段數量時的sql語句

今天對一個表A中字段進行查詢,不同類型的字段進行數據統計;


1.select  count(1)  from A  where strwhere 對符合條件的行數進行統計

2.select count(filed) from A  where strwhere 對符合條件列的行數進行統計,基本同上

下面纔是今天重頭戲

3.當字段存在類型,且爲0,1時,最爲簡單,但常用如:1.男,女;2.是,否;等可以用 0,1來作爲類型的正反類型時;

select sum(filde1),sum(filde2) from A where strwhere

當 查詢多個字段,且爲固定類型時(typeA,typeB。。。。)

4. select  sum(case when  filed1=typeA1  then 1 else 0 end),sum(case when  filed2=typeA2 then 1 else 0 end) from A  where strwhere

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