Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL ORDER BY issue
    text
    copied!<p>Duplicate of this <a href="https://stackoverflow.com/questions/810599/order-by-with-decode-function-issue-with-multiple-columns">question</a>, which itself cross-references 3 other minor variants of the same question.</p> <hr> <p>Hi all,</p> <p>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</p> <pre><code>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, ; </code></pre> <p>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.</p> <p>When,sort_key :='name'.As we can see it evaluates to a constant and then the remaining columns in the ORDER BY clause.</p> <p>Now,when variable sort_key:= 'description' or 'memberCount'....each of the values, then the ORDER BY LOGIC is different for each of them.</p> <p>As an example,when 'description' is selected-the sorting in the ORDER BY cluase should do as it does for 'name'.</p> <p>Example like this:-</p> <pre><code> UPPER(SUBSTR(group_description, 1, 1)), SUBSTR(group_description, 1, 1) DESC, UPPER(group_description), group_description DESC, group_description_key, </code></pre> <p>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.</p> <p>If its possible with order by CASE with all the options-can you please help me.I need your help very much</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload