您的位置:首頁技術文章
文章詳情頁

mysql - SQL查詢排序OrderBy

瀏覽:88日期:2022-06-16 15:53:43

問題描述

1.我要查詢課程排序,有三種狀態:正在上課、即將上課、已結束2.大排序按,正在上課、即將上課、已結束3.小排序,正在上課、即將上課(按時間正序),已結束(按時間倒序)

如何在一個SQL中實現

問題解答

回答1:

正在上課、即將上課、已結束 對應status 1,2,3

select *from table order by status,case status when 1 then sorttime end asc,case status when 2 then sorttime end asc,case status when 3 then sorttime end desc;

回答2:

select status, time ,(case when status = ’1’ then time when status = ’2’ -time end) sorttime from class order by status,sorttime

相關文章:
国产综合久久一区二区三区