listagg的订单未按照列表数据升序 [英] Order by listagg is not ascending according the list data
问题描述
我在如何根据列表升序中遇到问题.例如,我有一个表字段名称为mhn.kod_urusan.我想根据我键入的列表显示结果.问题是数据不符合我在列表中键入的内容. 和('PBPTG','PBMT')中的mhn.kod_urusan"
i have problem how to ascending the data according the list. For example, i have a table field names mhn.kod_urusan. i want to show the result according the list that i type.The problem is the data not follow what i type in the list. "and mhn.kod_urusan in ('PBPTG','PBMT')"
This is my query:-
select LISTAGG (upper(aa.kod_urusan), ', ') within Group (order by aa.kod_urusan asc) as daerah
from
(select distinct
mhn.kod_urusan,kc.nama nm
from
mohon mhn, kod_urusan ku, kod_caw kc
where
mhn.kod_urusan = ku.kod(+)
and mhn.kod_caw = kc.kod(+)
and (mhn.trh_masuk <= sysdate )
and mhn.kod_urusan in ('PBPTG','PBMT')
and mhn.kod_caw = '01'
order by mhn.kod_urusan asc )aa
This is the result:-
--Daerah--
PBMT, PBPTG
有人知道出什么问题吗?
Anyone know what the problem?
推荐答案
PBMT比PBPTG短,所以结果还可以
PBMT is shorter than PBPTG so result is ok
如果需要自定义排序顺序,则必须在表mohon
中添加一些int列,将其设为int myordercol
;
if you need custom sort order, you have to add some int column to table mohon
, let it be int myordercol
;
对于kod_urusan
中所有不同的值,应使用类似以下查询:
for all different values in kod_urusan
you should use queries like:
update mohon set myordercol = 1 where kod_urusan='PBPTG';
update mohon set myordercol = 2 where kod_urusan='PBMT';
.. and so on, so in such way you're establishing custom order for this columns
在此之后,您将需要更改order by子句以将该列用作排序字段
after this you will need to change your order by clauses to use this column as sorting field
这篇关于listagg的订单未按照列表数据升序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!