前一阶段发了一个帖子,得到了大家的帮忙。
http://topic.csdn.net/u/20091216/11/3527ff34-0c2a-4121-9a53-8f74b0ed1dda.html
现在我想在这个基础上增加一列,列中显示当前设备被使用人数。比如计算机被三个人使用,就是3.
aid assetname  person num
  1  计算机    张三    3
  1  计算机    赵六    3
  1  计算机    李四    3
  2  椅子      王五    2
  2  椅子      赵六    2
  3  桌子      冯七    1

解决方案 »

  1.   

    select dense_rank()over(order by assetname)aid, 
      assetname,person ,
      count(1)over(partition by assetname)num
    from table1 
    order by 1 
      

  2.   

    select sum(1) over(partition by assetname) , aid,assetname,person from t;
      

  3.   

    select dense_rank()over(order by assetname)aid, 
      assetname,person , 
      count(1)over(partition by assetname)num 
    from 表名
    order by 1
      

  4.   

    select t.aid ,t.assetname , t.person , 
           (select count(1) from tb where aid = t.aid) num
    from tb t