第一种方法 CASE WHEN beginTime IS NULL
THEN 0 ELSE 1 END
SELECT
LEFT(endTime, 10) AS validDate,
beginTime,
endTime,
COUNT(0) AS ticketNum,
ticketType,
ticketState
FROM
t_ticket
WHERE 1 = 1
AND userId = 10000
GROUP BY beginTime,
endTime,
ticketType
ORDER BY CASE WHEN beginTime IS NULL
THEN 0 ELSE 1 END,createTime DESC
LIMIT 0, 10
第二种方法 INSTR('',beginTime)
SELECT
LEFT(endTime, 10) AS validDate,
beginTime,
endTime,
COUNT(0) AS ticketNum,
ticketType,
ticketState
FROM
t_ticket
WHERE 1 = 1
AND userId = 10000
GROUP BY beginTime,
endTime,
ticketType
ORDER BY INSTR('',beginTime),createTime DESC
LIMIT 0, 10