1

我有以下 Order By 我希望以 ROID 顺序输出。相反,输出按 OIDR 顺序显示。为什么 R 会在结尾而不是开头?

select narritive_section as ns, decode(narritive_section,'R','Origin','O','Initial Observation','I','Investigation','D','Disposition') as narritive_section 
    ,person_id, offense_id, entry_date, narritive_text, c_narritive_text  
from t_narritive 
where not narritive_text is null and offense_id =  11514
order by offense_id, decode(
    narritive_section, 'R',1, 'O',2, 'I',3, 'D',4);
4

1 回答 1

1

您的 offence_id 具有更高的排序优先级,然后是 ROID 排序。按顺序切换两个参数应该可以解决您的问题。

select narritive_section as ns, decode(narritive_section,'R','Origin','O','Initial Observation','I','Investigation','D','Disposition') as narritive_section, person_id, offense_id, entry_date, narritive_text, c_narritive_text
from t_narritive
where not narritive_text is null and offense_id = 11514
order by decode(narritive_section, 'R',1, 'O',2, 'I',3, 'D',4), offense_id;
于 2013-08-08T21:24:25.060 回答