慕雪6442864
use tempdb godeclare @tb table(name nvarchar(20),sex nvarchar(10))insert into @tb select '张三','男'union allselect '李四','男'union allselect '王五','男'union allselect '赵六','女'union all select '曹七','女'select * from @tbdeclare @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 @newtbselect * from @tbman union allselect * from @tbwoman order by IDselect * from @newtb