这个插入新表的语句该怎么写??

xihuluyou 2005-02-02 04:00:56
sql="select distinct a.totalper from allgather as a,userinfo as b where a.uid=b.uid and a.totalField>=20 order by a.totalper DESC"

这一句是求出用户的排名并且按照一定规律返回
返回的结果是这样
100%
90%
80%

现在要把这一句改写成:
求出结果并且排列起来 插入到一张新表里,同时要增加一个序列号,新表里的返回结果应该是这样的:
1 100%
2 90%
3 80%

语句该怎么写啊?求教各位
...全文
60 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lypzl 2005-02-02
  • 打赏
  • 举报
回复
select identity(int,1,1) as id,* into #T
from (select distinct a.totalper from allgather as a,userinfo as b where a.uid=b.uid and a.totalField>=20 order by a.totalper DESC)t

select * from #T
JafyLiu 2005-02-02
  • 打赏
  • 举报
回复
select distinct identity(int,1,1) as id,a.totalper into #t
from allgather as a,userinfo as b
where a.uid=b.uid and a.totalField>=20
order by a.totalper DESC
lengxiaowei 2005-02-02
  • 打赏
  • 举报
回复
create table 新表
(
id int identity(1,1),
totalper varchar(100)
)

insert into 新表(totalper)
select distinct a.totalper from allgather as a,userinfo as b where a.uid=b.uid and a.totalField>=20 order by a.totalper DESC
wxlys 2005-02-02
  • 打赏
  • 举报
回复
同意!
JasonHeung 2005-02-02
  • 打赏
  • 举报
回复
支持
xluzhong 2005-02-02
  • 打赏
  • 举报
回复
select identity(int,1,1) as id,* into ##T
from (select distinct a.totalper from allgather as a,userinfo as b where a.uid=b.uid and a.totalField>=20 order by a.totalper DESC)t

select * from ##T

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧