資料庫統計不同欄位數量時的sql語句,欄位數量sql語句

來源:互聯網
上載者:User

資料庫統計不同欄位數量時的sql語句,欄位數量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

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.