我的数据库有两个表,一个是车号表,一个是单位编码表
车号表的字段是单位编码,车号
每个单位都有自己的车号
我想设置成,在车号表中,每个单位都具有同一个车号
比如单位编码1001的单位有99999这个车号
单位编码1002的单位也有99999这个车号
怎么用最快捷的方式实现,如果一个单位一个单位的输入,就太多了
最好用一条SQL语句实现
车号表的字段是单位编码,车号
每个单位都有自己的车号
我想设置成,在车号表中,每个单位都具有同一个车号
比如单位编码1001的单位有99999这个车号
单位编码1002的单位也有99999这个车号
怎么用最快捷的方式实现,如果一个单位一个单位的输入,就太多了
最好用一条SQL语句实现
go
update 车号表 set 车号 = '99999'
go
^_^
车号表:单位编码 车号
001
001
001
002
002
003
003 得到
单位编码 车号
001 1234
001
001
002 1234
002
003 1234
003
alter table w add cid int identity(1,1)
update w
set 车号='1234'
where cid
in (
select cid from w as A
where cid in ( select top 1 cid from w where 单位编码=A.单位编码))
alter table drop column cid
select 单位编码,'999999' from 车号表 group by 单位编码