Mybatis 時間排序讓空值NULL排在後面
阿新 • • 發佈:2018-11-11
有一張通知(notification)表;
需求:
1.狀態(status)為釋出“on”要排在未釋出“off”前面;
2.先按釋出時間排序再按建立時間排序,釋出時間為空的要排在後面。
select * from notification;
id | content | status | create_time | publiish_time |
1 | aaa | on | 2018-10-17 12:45:00 | 2018-10-17 12:45:00 |
2 | bbb | off | 2018-10-17 12:45:00 | |
3 | ccc | on | 2018-10-17 12:45:00 | 2018-10-17 12:45:00 |
4 | ddd | on | 2018-10-17 12:45:00 | 2018-10-17 12:45:00 |
5 | eee | off | 2018-10-17 12:45:00 |
<select id="getResultList" parameterType="com.hekliu.NotificationQry" resultMap="BaseResultMap"> SELECT <include refid="Base_Column_List"/> FROM notification WHERE 1 = 1 <if test="content != null and content !=''"> AND content = #{content} </if> <if test="status != null and status != ''"> AND status = #{status} </if> <if test="startPublishDate != null and startPublishDate != ''"> AND <![CDATA[DATE_FORMAT(publish_time,'%Y-%m-%d %H:%i:%s') >= #{startPublishDate}]]> </if> <if test="endPublishDate != null and endPublishDate != ''"> AND <![CDATA[DATE_FORMAT(publish_time,'%Y-%m-%d %H:%i:%s') <= #{endPublishDate}]]> </if> ORDER BY status = "off", status = "on", create_time DESC, publish_time is NULL, publish_time DESC </select>
原文連結:https://blog.csdn.net/liu59412/article/details/83141566