select IDENTITY(int, 1,1) 序列,*,cast(100.0*金额/(select sum(金额) from 表) as varchar(10))+'%' 金额比例 into #temp from 表 select * from #temp
select 序列,产品, 金额, 金额/(select sum(金额) from yourtable) from yourtable
select a.*,cast((a.金额+0.0)/(select sum(金额) from 表) as varchar(10)+'%' as 金额比例 from 表 a
select IDENTITY(int, 1,1) 序列,*,cast(100.0*金额/(select sum(金额) from 表) as varchar(10))+'%' 比例 into #temp from 表 select * from #temp drop table #temp --------删掉临时表
没有主键的情况: 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
select * from #temp
select * from #temp
drop table #temp --------删掉临时表
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