View previous topic :: View next topic |
Author |
Message |
manasa paduru Beginner
Joined: 20 Jul 2007 Posts: 2 Topics: 2
|
Posted: Thu Jan 06, 2011 8:42 am Post subject: DB2 Query To Change the order of rows |
|
|
1) I have a table ABCD where, when I give select, I get the following output
Code: |
RECTY
======
A0100
A0101
A0102
A0103
A0104
Z0105
Z0106
B0107
B0108
B0109
B0110
|
We need the output to be in the order of
Code: |
Z0105
Z0106
A0100
A0101
A0102
A0103
A0104
B0107
B0108
B0109
B0110
|
Please provide a select statement which would result in the above output.
Canyou please help me. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12381 Topics: 75 Location: San Jose
|
Posted: Thu Jan 06, 2011 11:57 am Post subject: |
|
|
manasa paduru,
Please post your queries to the right section. DB2 questions should be posted in DATABASE section. If these questions are part of interview then please post the questions in the Interview Q & A forum at the bottom.
Untested SQL
Code: |
SELECT RECTY
FROM ABCD
ORDER BY CASE WHEN SUBSTR(RECTY,1,1) = 'Z'
THEN ' ' || SUBSTR(RECTY,2,4)
ELSE RECTY END
;
|
Kolusu |
|
Back to top |
|
 |
|
|