문제

I have a stored procedure that fetches data and currently orders it as follows:

ORDER BY    dateEsc desc, prio desc, EID desc

Is there a way that I can say IF prio = "Urgent" THEN put such a record on the very top of my results and only for the remaining records apply the above order ?

도움이 되었습니까?

해결책

Something like the following will work, because when prio = 'Urgent' then the new condition will generate 0 else 1 and sort by this value first; and later sort by other conditions...

ORDER BY CASE WHEN prio = "Urgent" THEN 0 ELSE 1 END,
    dateEsc desc, prio desc, EID desc
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top