select *,金额/总金额 as 金额比率 from tablename a , (select sum(金额) as 总金额 from tablename ) T

解决方案 »

  1.   

    select IDENTITY(int, 1,1) 序列,*,cast(100.0*金额/(select sum(金额) from 表) as varchar(10))+'%' 金额比例 into #temp from 表
    select * from #temp
      

  2.   

    select 序列,产品, 金额, 金额/(select sum(金额) from yourtable) from yourtable
      

  3.   

    select a.*,cast((a.金额+0.0)/(select sum(金额) from 表) as varchar(10)+'%' as 金额比例 from 表 a
      

  4.   

    select IDENTITY(int, 1,1) 序列,*,cast(100.0*金额/(select sum(金额) from 表) as varchar(10))+'%' 比例 into #temp from 表
    select * from #temp
    drop table #temp   --------删掉临时表
      

  5.   

    没有主键的情况:
    select identity(int,1,1) as XH, * into #t from users
    go
    select * from #t order by XH
    go
    有主键的情况:
    select (select count(*) from users where TID <= A.TID) as XH, * from users as A
     order by TID