1 回答

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
use tempdb
go
declare @tb table(name nvarchar(20),sex nvarchar(10))
insert into @tb
select '張三','男'
union all
select '李四','男'
union all
select '王五','男'
union all
select '趙六','女'
union all
select '曹七','女'
select * from @tb
declare @newtb table(name nvarchar(20),sex nvarchar(10),ID int)
declare @tbman table(name nvarchar(20),sex nvarchar(10),ID int identity(1,2))
declare @tbwoman table(name nvarchar(20),sex nvarchar(10),ID int identity(2,2))
insert into @tbman select * from @tb where sex='男'
insert into @tbwoman select * from @tb where sex='女'
insert into @newtb
select * from @tbman
union all
select * from @tbwoman
order by ID
select * from @newtb
添加回答
舉報(bào)