将查询结果作为条件,参与排序
SELECT id,
`name`,
start_time AS startTime,
end_time AS endTime,
`type`,
inner_type_id AS innerTypeId,
(
CASE
WHEN (start_time > CURRENT_TIMESTAMP()) THEN 0
WHEN (start_time <= CURRENT_TIMESTAMP() AND end_time >= CURRENT_TIMESTAMP()) THEN 1
WHEN (end_time < CURRENT_TIMESTAMP()) THEN 2
END
) AS status
FROM xxx_xx
<where>
del_flag = 0
<if test="status == 0">
AND start_time > CURRENT_TIMESTAMP() AND end_time > CURRENT_TIMESTAMP() AND forecast_flag = 1
</if>
<if test="status == 1">
AND start_time <= CURRENT_TIMESTAMP() AND end_time >= CURRENT_TIMESTAMP()
</if>
<if test="status == 2">
AND end_time < CURRENT_TIMESTAMP()
</if>
<if test="innerTypeId != null">
AND inner_type_id = #{innerTypeId}
</if>
</where>
ORDER BY status, sort, start_time DESC