表Table1,有两个字段ID和State,ID为主键,State可以取1-6个数字,现在如何用语句统计表Table1中有多少条State=6的纪录,有多少条不等于6的纪录?

解决方案 »

  1.   

    select count(*) as len6 ,all-len6from (
    select count(*) as all
    from t
    where 
    )
    where length(State)==6
      

  2.   


    SELECT COUNT(*) FROM Table1 WHERE STATE=6
    SELECT COUNT(*) FROM Table1 WHERE STATE<>6
      

  3.   


    select count(*) as len6 ,all-len6from (
    select count(*) as all
    from t
      --多了个where 
    )
    where length(State)==6
      

  4.   

    select id, sum(decode(state,6,1,0)) state6, sum(decode(state,6,0,1)) state_no6
      from table1 group by id;