There is a table ACCOUNT_SCENARIO:
In which there is a column ACCOUNT_TYPE, which reflects the hierarchy, of which only 3 - 'CE', 'CF', 'SP'.
Is it possible to sort the table first for the first hierarchy, then for the second and at the end for the 3rd? At the same time, each subsequent sorting should not affect the previous one.
But actually the sorting algorithm itself (sorted by a column from another table under the name ACCOUNT_HIERARCHY):
SELECT ACSC.* FROM ACCOUNT_SCENARIO AS ACSC JOIN (SELECT PARENT_ACCOUNT_ID, MIN(EXCEL_ORDER) AS EXCEL_ORDER FROM ACCOUNT_HIERARCHY WHERE ACCOUNT_HIERARCHY_ID = 'SP' GROUP BY PARENT_ACCOUNT_ID ) X ON ACSC.ACCOUNT_ID = X.PARENT_ACCOUNT_ID WHERE ACCOUNT_TYPE = 'SP' ORDER BY ACCOUNT_TYPE, X.EXCEL_ORDER, ACCOUNT_DATE 
case when then else endwith division multiplications, sort the branches in any order. - nick_n_aorder by (select a from table1 where table1.id = x.id)- nick_n_aorder by coalesce(case when ACCOUNT_TYPE='CE' then expression_1 end, case when ACCOUNT_TYPE='CF' then expression_2 end, case when ACCOUNT_TYPE='SP' then expression_3 end )I showed the subqueries. Next - try - succeed. - nick_n_a