MySQL Forums
Forum List  »  Stored Procedures

nested sorting using nested case statement
Posted by: Radhakant Samal
Date: January 26, 2011 11:36PM

i am trying to sort using case statement but in branching ie

suppose i hava a table which has state and district as two columns.
so when i am retrieving data first it should sort the state wise then
district name with respect to the state name.

order by state case
when state_1 then 1
when state_2 then 2
when state_3 then 3
else state
end;
what is my requirement is when it displays the state_1 then it should
display all the district related to state_1 in a sorted manner.

so if i am using nested case it displays error. i am using like below

order by state case
when state_1 then order by district case
when dis_1 then 1
when dis_2 then 2
.
.
.
end
when state_2 then order by district
.
.
when state_2 then order by district
.
.
end,
but it is not working, kindly let me know the correct way to get this.

Options: ReplyQuote


Subject
Views
Written By
Posted
nested sorting using nested case statement
3386
January 26, 2011 11:36PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.