|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
Advanced: sorting by non alphabetic criteria
i have a table with a varchar column. for simplicity lets say that it will always have a value of 'low', 'medium', 'high'.
when querying i want to sort records in order by low, medium, and high. sorting alphabetically using ORDER BY column ASC or DESC would not work the way I want it to. how can i define my own sort criteria? making another table and joining is out of the question. id also rather avoid creating temporary views or tables, and try to do this in one query if possible. thanks |
|
#2
|
|||
|
|||
|
Code:
select decode(vc,'High',1,'Medium',2,'Low',3,0) as sortOrder, <other columns> from t order by sortOrder Change names as apropriate. |
|
#3
|
|||
|
|||
|
If the value low, medium, high is not returned by select:
Code:
SELECT fld1,fld2
from table
order by case when fld3='LOW' 0
when FLD3='MEDIUM' 1
else 2
end;
|
|
#4
|
|||
|
|||
|
awesome.
thanks! |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Advanced: sorting by non alphabetic criteria |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|