Duplicate of this question, which itself cross-references 3 other minor variants of the same question.
Hi all,
I am sorry but i am putting my question as a new question in this post.I need all your help very much now and i appreciate your help very much
SELECT *
FROM (SELECT distinct gl.group_id,
gl.group_name,
gl.group_description,
gl.status_code,
gl.member_count,
(SELECT grpp.group_name
FROM test_group_relationship grel JOIN test_group grpp
ON grel.parent_group_id = grpp.group_id
WHERE grel.child_group_id = gl.group_id
) AS parent_group_name,
gl.group_name_key,
gl.group_description_key
FROM test_group AS gl
WHERE gl.group_org_id = '3909'
AND (gl.group_name_key LIKE '%GROUP%')
) AS data_set
ORDER BY DECODE(:sort_key,
'name', 'constant',
'description', group_description_key,
'memberCount', LPAD(member_count, 4),
'status', LPAD(status_code, 4),
'parentGroupName', parent_group_name
)NULLS FIRST,
UPPER(SUBSTR(group_name, 1, 1)),
SUBSTR(group_name, 1, 1) DESC,
UPPER(group_name),
group_name DESC,
group_name_key,
;
My question still remains the similar.I want dynamic sorting to be done based on the :sort_key variable which has one of the various options in the decode everytime to sort.
When,sort_key :='name'.As we can see it evaluates to a constant and then the remaining columns in the ORDER BY clause.
Now,when variable sort_key:= 'description' or 'memberCount'....each of the values, then the ORDER BY LOGIC is different for each of them.
As an example,when 'description' is selected-the sorting in the ORDER BY cluase should do as it does for 'name'.
Example like this:-
UPPER(SUBSTR(group_description, 1, 1)),
SUBSTR(group_description, 1, 1) DESC,
UPPER(group_description),
group_description DESC,
group_description_key,
In brief,each of the options that the sort_key variable gets-the ORDER BY logic is different and i have to implement it in the same SQL only now.
If its possible with order by CASE with all the options-can you please help me.I need your help very much