当前位置: 首页 > news >正文

查询列表实时按照更新时间降序排列 没有更新时间就按创建时间

例子:

sql两个字段排序

      ORDER  BY   update_time  DESC , create_time  DESC

    <select id="selectLawIllegalActivitiesList" parameterType="LawIllegalActivities" resultMap="LawIllegalActivitiesResult"><include refid="selectLawIllegalActivitiesVo"/><where>  <if test="illegalActivities != null  and illegalActivities != ''"> and illegal_activities like concat('%', #{illegalActivities}, '%')</if><if test="terms != null  and terms != ''"> and terms = #{terms}</if><if test="termsContent != null  and termsContent != ''"> and terms_content = #{termsContent}</if><if test="according != null  and according != ''"> and according = #{according}</if><if test="accordingContent != null  and accordingContent != ''"> and according_content = #{accordingContent}</if></where>ORDER  BY   update_time  DESC , create_time  DESC</select>
  /*** 查询违法事项库列表* * @param lawIllegalActivities 违法事项库* @return 违法事项库集合*/public List<LawIllegalActivities> selectLawIllegalActivitiesList(LawIllegalActivities lawIllegalActivities);

如果新增数据 只有创建时间 没有更新时间  想要新增数据排到最前面

ORDER BY 
  COALESCE(update_time, create_time) DESC,
  create_time DESC
 

这里使用了COALESCE函数,它会返回第一个非空参数的值。如果update_time是NULL,则COALESCE(update_time, create_time)将使用create_time的值进行排序。这样,无论是否有更新时间,所有记录都会按照最新的时间戳进行降序排列。

  <select id="selectLawIllegalActivitiesList" parameterType="LawIllegalActivities" resultMap="LawIllegalActivitiesResult"><include refid="selectLawIllegalActivitiesVo"/><where>  <if test="illegalActivities != null  and illegalActivities != ''"> and illegal_activities like concat('%', #{illegalActivities}, '%')</if><if test="terms != null  and terms != ''"> and terms = #{terms}</if><if test="termsContent != null  and termsContent != ''"> and terms_content = #{termsContent}</if><if test="according != null  and according != ''"> and according = #{according}</if><if test="accordingContent != null  and accordingContent != ''"> and according_content = #{accordingContent}</if></where>ORDER BYCOALESCE(update_time, create_time) DESC,create_time DESC</select>

http://www.lryc.cn/news/287571.html

相关文章:

  • 愉快的使用vscode刷leetcode,开启摸鱼新高度
  • openssl3.2/test/certs - 003 - genroot “Root CA“ root-key2 root-cert2
  • npm install出错的各种情况
  • 【Docker】Docker学习⑤ - Docker数据管理
  • C/C++ - 编程语法特性
  • Backtrader 文档学习-Target Orders
  • QT发生弹出警告窗口
  • vue3使用特殊字符@、~代替路径src
  • Java中的HTTPS通信
  • 威联通QNAP NAS结合cpolar内网穿透实现公网远程访问NAS中存储的文件
  • Ubuntu上安装部署Qt
  • MySQL的`FOR UPDATE`详解
  • 计算机网络 第4章(网络层)
  • HDD的烦恼:HAMR会让SMR黯然失色吗?
  • linux安装docker(入门一)
  • Node.js中fs模块
  • google-webrtc 原理
  • uniapp 框架搭建及使用
  • 嵌入式软件工程师面试题——2025校招社招通用(计算机网络篇)(三十二)
  • 《WebKit 技术内幕》学习之十一(4):多媒体
  • k8s基础知识
  • Docker容器引擎(3)
  • 【Android12】Android Framework系列---Adb和PMS安装apk源码流程
  • web漏洞总结大全(基础)
  • 获取双异步返回值时,如何保证主线程不阻塞?
  • hosts文件修改后无法保存的解决办法
  • 源码篇--Redis 五种数据类型
  • Sulfo Cy2 Biotin,水溶性 Cy2 生物素,能够与各种氨基基团特异性结合
  • NineData支持制定安全、可靠的SQL开发规范
  • LSTM时间序列预测