一个会员表里,怎么查询,才能使查出的结果是一行男一行女一行男一行女一行男一行女…………
1 回答
慕雪6442864
TA贡献1812条经验 获得超5个赞
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
添加回答
举报
0/150
提交
取消