扫码关注官方订阅号
1.我要查询课程排序,有三种状态:正在上课、即将上课、已结束2.大排序按,正在上课、即将上课、已结束3.小排序,正在上课、即将上课(按时间正序),已结束(按时间倒序)
如何在一个SQL中实现
业精于勤,荒于嬉;行成于思,毁于随。
正在上课、即将上课、已结束 对应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;
select status, time ,(case when status = '1' then time when status = '2' -time end) sorttime from class order by status,sorttime
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
正在上课、即将上课、已结束 对应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;