table Aid   num
001   1
001   2
001   3
002   4想用一条语句得到这个表的所有信息加上count(distinct(id))的条数id   num  newcoulunm
001   1      2
001   2      2
001   3      2
002   4      2

解决方案 »

  1.   

    一条sql语句实现表里的信息加上不同id的数量
      

  2.   

    select t.*,(select distinct id from t) newcolumn
    from t;
      

  3.   

    select t.*,(select count(distinct id) from table t) newcolumn 
    from table t; 
      

  4.   

    select a.id,a.num,b.newcoulunm  from A a inner join (select id,count(id) newcoulunm  from A group by id) b on a.id=b.id
      

  5.   

    select id,num count(id)over(partition by id order by id) as newcoulunm from a 
      

  6.   

    select A.*, B.Counts
    from 
       A,
       ( select Id, count(1) Counts from A group by Id ) B
    where A.Id = B.Id
      

  7.   

    纠正:
    select a.*,b.newcolumn
    from t a,
    (select id,count(distinct id) newcolumn from t group by id) b
    where a.id=b.id
      

  8.   

    select * from A,(select count(distinct id) newcoulunm  from A);