I am trying a different kind of sorting in Oracle.Its like I have three columns namely Date ,Start Time & End Time and I need to sort the column in the following fashion.
If the current time is in between Start Time and End time then that row should come @ the top.Otherwise it should be sorted by normal ascending order.
Right now my query looks like this
select * from details order by date,start_time
How can I take current time into consideration while sorting?
Szilard Barany :
First idea that came to my mind:\n\nSELECT *\nFROM details\nORDER BY ( CASE WHEN date_column BETWEEN start_time AND end_time THEN 0 ELSE 1 END )\n , date_column\n , start_time;\n",
2012-02-20T08:05:04
Justin Cave :
If \"current time\" means \"sysdate\", and assuming that \"sorted by normal ascending order\" means \"sort by start_time in ascending order\" you could do something like\n\nSELECT *\n FROM details\n ORDER BY (CASE WHEN sysdate BETWEEN start_time AND end_time \n THEN 1\n ELSE 0\n END) desc,\n start_time asc\n\n\nIf you mean something else, some sample data and the expected output would definitely help.",
2012-02-20T08:01:00