22,207
社区成员
发帖
与我相关
我的任务
分享
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 行)
*/
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 ,
case TimePointZone when '01' then '月'
when '02' then '年' when ‘03’ then ‘季’end TimePointZone
from tb
order by TimePointZone
select MeasureID ,SerialNo ,MeasureName ,
case TimePointZone when '01' then '月'
when '02' then '年' when ‘03’ then ‘季’end TimePointZone
from tb