文章详情页
mysql - SQL查询排序OrderBy
浏览:49日期: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. android - Listview模仿朋友圈点赞的TextView没有刷新?2. mysql - 索引过滤性不好是由什么原因引起的,应该怎么解决3. javascript - 修改表单多选项时和后台同事配合的问题。4. 网页爬虫 - Python:爬虫的中文编码问题?5. dockerfile - [docker build image失败- npm install]6. angular.js - angularjs 怎么封装 upload 上传7. javascript - vue生成一维码?求助!!!!!急8. docker内创建jenkins访问另一个容器下的服务器问题9. mysql - 我的myeclipse一直连显示数据库连接失败,不知道为什么10. javascript - H5页面怎么查看console信息?
排行榜
