加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQLSERVER 自增列

发布时间:2020-12-12 16:07:24 所属栏目:MsSql教程 来源:网络整理
导读:1.比如我需要某一列自增 ?就在下面写上该SQL select ?ROW_NUMBER()over(order by (select 1)) as tt,name,id? from s03_bak 只能做一个嵌套,按照你的,我建了几个表和查询,你看看,符合你要求不 建表 1 2 3 4 5 6 7 create ? table ? a?(id? int , name ?
1 2 3 4 5 6 7 create? table? a?(id?int,name? varchar(10)); ? ? b?((10),qty?);

插入数据

1 2 3 4 5 6 7 8 9 10 11 12 insert? into? a?values? (1,'张三')(2,monospace; border:0px!important; bottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; min-height:auto!important; margin:0px!important; padding:0px!important; color:blue!important">'李四')(3,monospace; border:0px!important; bottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; min-height:auto!important; margin:0px!important; padding:0px!important; color:blue!important">'王五')(4,monospace; border:0px!important; bottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; min-height:auto!important; margin:0px!important; padding:0px!important; color:blue!important">'赵六')(5,monospace; border:0px!important; bottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; min-height:auto!important; margin:0px!important; padding:0px!important; color:blue!important">'孙七') ? b?(

运行语句

1 2 3 4 select? t.nameorder? by? t.qty)from(a.sum(b.qty)?qty??from? a?left? join? on? =b.group? )?t

?

结果截图

向左转|向右转

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

1.比如我需要某一列自增 ?就在下面写上该SQL


select ?ROW_NUMBER()over(order by (select 1)) as tt,name,id?

from s03_bak



只能做一个嵌套,按照你的,我建了几个表和查询,你看看,符合你要求不

建表

    推荐文章
      热点阅读