View previous topic :: View next topic |
Author |
Message |
arvibala Beginner

Joined: 12 Feb 2008 Posts: 142 Topics: 67
|
Posted: Fri Sep 24, 2010 7:46 am Post subject: Order Sequence in a Query |
|
|
I have a table from which I need to extract data for a report. Only Order sequence to pull data using a query that I know of is Ascending or Descending. Can I be helped with a better query so that I can order my results in my way other than Ascending or Descending ?
For example I have a column (OPTION) which can have only below data
I want the records to be sorted on this but in below order using a query.
I heard we can do this in Oracle, but can we in DB2?
[/code] _________________ Arvind
"You can make a difference with your smile. Have that with you always" |
|
Back to top |
|
 |
Sqlcode Intermediate
Joined: 15 Dec 2006 Posts: 157 Topics: 38
|
Posted: Fri Sep 24, 2010 9:32 am Post subject: |
|
|
Arvind,
Quote: | Only Order sequence to pull data using a query that I know of is Ascending or Descending. |
Please explain the rules to get the expected output? How do you get Z after A and then F?
Thanks, |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Fri Sep 24, 2010 10:39 am Post subject: |
|
|
arvibala,
If you just want to change the order for some of the characters, then you can use a case statement and assign some sorted values and use that in order by.
Here is an untested SQL
Code: |
SELECT A.COL1
FROM (SELECT COL1 AS COL1
,CASE WHEN COL1 = 'Z' THEN CHAR('B')
WHEN COL1 = 'F' THEN CHAR('C')
ELSE COL1 END AS SEQ
FROM your_table) A
ORDER BY A.SEQ
; |
|
|
Back to top |
|
 |
|
|