文章詳情頁
mysql - SQL查詢排序OrderBy
瀏覽:68日期: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
相關文章:
1. mysql優化 - mysql count(id)查詢速度如何優化?2. mysql主從 - 請教下mysql 主動-被動模式的雙主配置 和 主從配置在應用上有什么區別?3. angular.js - angularjs 用ng-reapt渲染的dom 怎么獲取上面的屬性4. 主從備份 - 跪求mysql 高可用主從方案5. css3 - [CSS] 動畫效果 3D翻轉bug6. node.js - node_moduls太多了7. python如何不改動文件的情況下修改文件的 修改日期8. python - django 里自定義的 login 方法,如何使用 login_required()9. angular.js - 不適用其他構建工具,怎么搭建angular1項目10. css3 - css before作為父級元素的背景色遮住了文字怎么辦?
排行榜
![css3 - [CSS] 動畫效果 3D翻轉bug](http://www.aoyou183.cn/attached/image/news/202304/110831f073.png)