sql - Ordering the query results based on the order given inside the IN clause -
i order result set of sql query based on order inside in clause example:
select * employee empid='eng' , deptid in ('software','mech','aero','civil'),
for above query order result set in order 1. software, 2. mech, 3. aero, 4. civil
in oracle, use instr()
or case
:
select * employee empid='eng' , deptid in ('software','mech','aero','civil') order instr('software,mech,aero,civil', deptid)
this should work in db2.
the case
form work in both databases, longer:
order (case deptid when 'software' 1 when 'mech' 2 when 'aero' 3 when 'civil' 4 end)
Comments
Post a Comment