Mysql分组查询CaWhen

更新时间:2023-07-14 21:52:42 阅读: 评论:0

Mysql分组查询CaWhen
需求是这样的: 我的考试列表分页查询。
1. 进⾏中的 end>now >start)
2. 待开始的(now <start)
蒜泥茄子3. 已结束(end<now)
am_id AS examId,t1.id AS id,t1.state AS examResult,t1.submit_time AS submitTime,t1.score AS score,
t1.ur_exam_mongo_id AS urExamMongoId, t1.anr_mongo_id AS anrMongoId,t1.answer_times AS
装聋做哑
answerTimes,t1.answer_id AS answerId,
柔软时光t2.title AS ded_at AS endedAt,t2.max_answer_time AS maxAnswerTime,t2.started_at AS
startedAt,t2.max_answer_times AS maxAnswerTimes, t2.publish_result_state AS publishResultState
蛇盘疮吃什么药
FROM mtk_exam_urs t1 INNER JOIN mtk_exams t2 ON t2.id = t1.exam_id
WHERE t1.ur_id = 95 am_type='official'
-- and (t2.title like %%)
-- and ca when ?4 is null then 1=1 when ?4=1 then t2.started_at>?9 when ?4=2 then t2.started_at<=?9 and
-- and ca when ?5 is null then 1=1 when ?5=2 then (t1.state=?5 or (t1.state in (3,4) and
t2.publish_result_state=0)) el (t1.state=?5 and t2.publish_result_state=1) end
大树小树>泰国红宝石-- and (?6 is null or t2.category_id=?6)30岁创业
-- and t1.is_delete=0 and t2.is_delete=0 lea_state=1 and t2.file_state=0
ORDER BY CASE WHEN TO_DAYS(NOW()) BETWEEN TO_DAYS(t2.started_at) AND TO_ded_at) THEN 0 WHEN TO_DAYS(NOW()) < TO_DAYS(t2.started_at) THEN 1 ELS
E 2 END , t2.started_at DESC
有个问题是对于今天的考试(还没开考的试卷)是倒序排列的,实际希望今天未开始考试的是按时间升序。有SQL⼤神的留⾔指点下。
实际希望的是:马卡鲁峰
今天待开始的(按start升序)>今天进⾏中的(按start降序)>除今天待开始的(按start降序)>已结束的(按start降序)

本文发布于:2023-07-14 21:52:42,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1096773.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:考试   希望   实际
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图