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

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -