文章详情页
mysql - SQL查询排序OrderBy
浏览:69日期: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. angular.js - 不适用其他构建工具,怎么搭建angular1项目3. mysql主从 - 请教下mysql 主动-被动模式的双主配置 和 主从配置在应用上有什么区别?4. python - django 里自定义的 login 方法,如何使用 login_required()5. 主从备份 - 跪求mysql 高可用主从方案6. node.js - node_moduls太多了7. java8中,逻辑与 & 符号用在接口类上代表什么意思8. python如何不改动文件的情况下修改文件的 修改日期9. angular.js - Angular路由和express路由的组合使用问题10. python - 关于ACK标志位的TCP端口扫描的疑惑?
排行榜
