# 关于 sql server 2000 排序问题

qdwangqun 2010-09-17 04:35:21

----
MeasureID SerialNo MeasureName TimePointZone
Z00002009000120 000008 利润总额 01
Z00002009000121 000001 预算值 01
Z00002009000018 000007 煤炭货运量 03
Z00002009000022 000008 同国内行业 03
Z00002009000022 000005 吞吐量 02
----

-----------
MeasureID SerialNo MeasureName TimePointZone
Z00002009000120 000008 利润总额 月
Z00002009000121 000001 预算值 月
Z00002009000022 000005 吞吐量 年
Z00002009000018 000007 煤炭货运量 季
Z00002009000022 000008 同国内行业 季
-----------

...全文
64 点赞 收藏 4

4 条回复

dawugui 2010-09-17
create table tb (MeasureID varchar(20),SerialNo  varchar(20),MeasureName  varchar(20),TimePointZone  varchar(20))
insert into tb values('Z00002009000120', '000008', '利润总额' , '01')
insert into tb values('Z00002009000121', '000001', '预算值' , '01')
insert into tb values('Z00002009000018', '000007', '煤炭货运量', '03')
insert into tb values('Z00002009000022', '000008', '同国内行业', '03')
insert into tb values('Z00002009000022', '000005', '吞吐量' , '02')
go

select MeasureID ,SerialNo ,MeasureName ,TimePointZone =
case when TimePointZone = '01' then '月'
when TimePointZone = '02' then '年'
when TimePointZone = '03' then '季' end
from tb
order by case when TimePointZone = '01' then 1 when TimePointZone = '02' then 2 else 3 end

select MeasureID ,SerialNo ,MeasureName ,TimePointZone =
case when TimePointZone = '01' then '月'
when TimePointZone = '02' then '年'
when TimePointZone = '03' then '季' end
from tb
order by TimePointZone

drop table tb

/*
MeasureID SerialNo MeasureName TimePointZone
-------------------- -------------------- -------------------- -------------
Z00002009000120 000008 利润总额 月
Z00002009000121 000001 预算值 月
Z00002009000022 000005 吞吐量 年
Z00002009000018 000007 煤炭货运量 季
Z00002009000022 000008 同国内行业 季

（所影响的行数为 5 行）
*/

dawugui 2010-09-17
select MeasureID ,SerialNo ,MeasureName ,TimePointZone =
case when TimePointZone = '01' then '月'
when TimePointZone = '02' then '年'
when TimePointZone = '03' then '季' end
from tb
order by case when TimePointZone = '01' then 1 when TimePointZone = '02' then 2 else 3 end

zsh0809 2010-09-17
select MeasureID ,SerialNo ,MeasureName ,
case TimePointZone when '01' then '月'
when '02' then '年' when ‘03’ then ‘季’end TimePointZone
from tb
order by TimePointZone

zsh0809 2010-09-17
select MeasureID ,SerialNo ,MeasureName ,
case TimePointZone when '01' then '月'
when '02' then '年' when ‘03’ then ‘季’end TimePointZone
from tb

2.1w+

MS-SQL Server 疑难问题

2010-09-17 04:35