文章详情页
mysql - SQL查询排序OrderBy
浏览:234日期: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. python - tweepy 库 连接Twitter API 报错2. python - django 项目的 migrations 目录是否应该提交到 git3. mysql - SQL添加记录的数据来源于同一个表4. python小白的基础问题 关于while循环的嵌套5. 怎样写一个时间到了或是有订单的语音提醒呢?6. windows-7 - Win7中Vmware Workstatoin与Xampp中Apache服务器端口冲突?7. python - 怎么通过vpn连内网ftp?8. python - 使用ajax向django后台请求静态页面,返回200,但是页面不渲染出来9. 为什么说非对象调用成员函数fetch()10. mysql - 数据库字段命名问题,新人,求解
排行榜

网公网安备