MYSQL之end_time 小于当前时间降序排列 ,end_time 大于当前时间升序排列

 

怎么排不满足条件都在最后边

SELECT
	*, DATEDIFF(end_time, NOW()) AS c
FROM
	case_lawyer_expand
ORDER BY
	0 > DATEDIFF(end_time, NOW()),
	end_time DESC

end_time 小于当前时间降序排列 ,end_time 大于当前时间升序排列  下边sql加入创建时间升序排列

SELECT
	*, DATEDIFF(end_time, NOW()) AS c
FROM
	case_lawyer_expand
ORDER BY
	NOW() > end_time,

IF (NOW() > end_time, 0, end_time),
 end_time DESC
SELECT
	*, DATEDIFF(end_time, NOW()) AS c
FROM
	case_lawyer_expand
ORDER BY
	NOW() > end_time,

IF (NOW() > end_time, 0, end_time),
 end_time DESC,
 gmt_created ASC
SELECT
	case_id,
	end_time,
	gmt_created,
	DATEDIFF(end_time, NOW()) AS c
FROM
	case_lawyer_expand
ORDER BY
	NOW() > end_time,
IF (NOW() > end_time, 0, end_time),
 end_time DESC,
IF (NOW() > end_time, 0, gmt_created),
 gmt_created DESC

https://blog.csdn.net/u011447905/article/details/80013987

你可能感兴趣的:(MYSQL之end_time 小于当前时间降序排列 ,end_time 大于当前时间升序排列)