视图 A,下面例子简单,实际工作上比这复杂
select count(*) a from t_list t
group by t.id视图结果
a
1
1
2
3
4
5
5
6
6
7我要统计这个视图结果里 =1的数量,等于2的数量,依此类推
谢谢了

解决方案 »

  1.   

    select t1.a, count(t1.a)
    from (
      select count(*) a
       from t_list t
      group by t.id ) t1
    group by t1.a;
      

  2.   


    select a,count(1)
    from A
    group by A
      

  3.   

    WITH T AS select MAX(A) CNT
    from t_list
    ,
    SELECT LEVEL,COUNT(1) 数量 FROM t_list
    CONNECT BY LEVEL<=T.CNT
    GROUP BY LEVEL;
      

  4.   

    谢谢,各位,我之前还有两种情况忘了说了
    应该是<3,等于4,等于5,等于6,>7
    看来那两种大小于的只能再查询一次视图了吧 ?
      

  5.   

    select sum(case when a = 1 then 1 else 0 end) "a=1",
    sum(case when a = 2 then 1 else 0 end) "a=2",
    sum(case when a < 3 then 1 else 0 end) "a<1",
    sum(case when a = 4 then 1 else 0 end) "a=4",
    sum(case when a = 5 then 1 else 0 end) "a=5",
    sum(case when a = 6 then 1 else 0 end) "a=6",
    sum(case when a > 7 then 1 else 0 end) "a>7"
    from temp
      

  6.   

    select sum(case when a = 1 then 1 else 0 end) "a=1",
    sum(case when a = 2 then 1 else 0 end) "a=2",
    sum(case when a < 3 then 1 else 0 end) "a<1",
    sum(case when a = 4 then 1 else 0 end) "a=4",
    sum(case when a = 5 then 1 else 0 end) "a=5",
    sum(case when a = 6 then 1 else 0 end) "a=6",
    sum(case when a > 7 then 1 else 0 end) "a>7"
    from temp
      

  7.   

    谢谢 Phoenix_99 super_stan
      

  8.   


    SELECT COUNT(1),COUNT(1) OVER(PARTITION BY COUNT(1)) 
    FROM   t_list t
    group by t.id