上面的是Oracle语句。
如果是SQL Server的话,恐怕就得:
select 身份证号码、姓名、性别, 类别, 状态
from 职工情况表
where 类别='市城镇职工'
order by 状态,身份证号码
union
select 身份证号码、姓名、性别, 类别, 状态
from 职工情况表
where 类别='外地城镇职工'
order by 状态,身份证号码
union
select 身份证号码、姓名、性别, 类别, 状态
from 职工情况表
where 类别='本地农民工'
order by 状态,身份证号码
union
select 身份证号码、姓名、性别, 类别, 状态
from 职工情况表
where 类别='外地农民工'
order by 状态,身份证号码
select 身份证号码、姓名、性别, 类别, 状态
from
(select 身份证号码、姓名、性别, 类别, 状态
decode(类别,'市城镇职工',1
'外地城镇职工',2
'本地农民工',3
'外地农民工',4) as 类别代码,
decode(状态,'在职',1
'离职',2) as 状态代码
from 职工情况表) t
order by t.类别代码, t.状态代码, t.身份证号码
select * from mployees order by 状态,身份证号码 where 类别 = '本市城镇职工'
union
select * from mployees order by 状态,身份证号码 where 类别 = '外地城镇职工'
union
select * from mployees order by 状态,身份证号码 where 类别 = '本市农民工'
union
select * from mployees order by 状态,身份证号码 where 类别 = '外地农民工'
就是一条普通的order by 语句吧,such as:
select *,类别2=(case 类别 when '本市城镇职工' then 1 when '外地城镇职工' then 2 when '本地农民工' then 3 else 4 end),状态2=(case 状态 when '在职' then 1 else 2 end) from tg_deedstate order by 类别2,状态2,身份证号码