create table test (CPBH char(7),LSH int default 0)
insert test(CPBH) select '6666122'
insert test(CPBH) select '6666122'
insert test(CPBH) select '6666122'
insert test(CPBH) select '6666133'
insert test(CPBH) select '6666133'
insert test(CPBH) select '5454465'
insert test(CPBH) select '5451165'
insert test(CPBH) select '4541165'
insert test(CPBH) select '4541165'
insert test(CPBH) select '5555511'
--select * from test
alter table test
add id int identity(1,1)
go
update test set
LSH=
(
select count(*)+1 from test where cpbh=a.cpbh and id<a.id ----内层表为引用表,因为肯定有一条记录不符合id<a.id, 所以0,1,2
) from test a ------外层表
alter table test
drop column id
go
select * from test
drop table test
本文演示了如何使用SQL创建表、插入数据、更新字段、删除列及最终显示表内容等操作。通过具体的SQL语句展示了表结构的修改过程。
4万+

被折叠的 条评论
为什么被折叠?



