我正在尝试在状态列表中返回“最大值”。但是,我想为字符串值分配一个排序值,以便最大值由我自己的排名返回,而不是按字母顺序。
这是我的代码:
select x.wbs1, x.wbs2, x.wbs3, x.custstatus
from (
select wbs1,wbs2,wbs3,custstatus=MAX(custstatus)
from Projects_CRStatus
where custsentdate >= 'June 1, 2001' AND custsentdate <= 'June 30, 2013'
AND CustStatus IN ('RECEIVED AT VENDOR', 'CONFIRMATION SENT',
'IC PENDING','CONFIRMATION RECEIVED','CANCELLED')
group by wbs1,wbs2,wbs3 ) x
inner join (
select wbs1,wbs2,wbs3,custsentdate=max(custsentdate)
from Projects_CRStatus
group by wbs1,wbs2,wbs3) y
on (x.wbs1=y.wbs1 and x.wbs2=y.wbs2 and x.wbs3=y.wbs3)
ORDER BY CustEnrollmentID
我想做的是对 CustStatus 的值进行排名,这样我就不会返回 CustStatus 的最高字母结果,而是按此顺序获得最高级的状态。
- '在供应商处收到'
- '确认已发送'
- 'IC 待定'
- '收到确认'
- '取消'