Mysql 去重取最新的一条数据

SELECT
	id,
	job_id,
	start_time,
	end_time,
	cost_time,
	STATUS,
	error_message
FROM
	(
		SELECT
			id,
			job_id,
			start_time,
			end_time,
			cost_time,
			STATUS,
			error_message,

		IF (
			@jobid = job_id,
			@num :=@num + 1,
			@num := 1
		) AS num,
		@jobid := job_id
	FROM
		pybee_job_detail
	ORDER BY
		job_id,
		end_time DESC
	) tab
WHERE
	num = 1;

  

posted @ 2021-09-27 11:43  好记性不如烂笔头-贾  阅读(2137)  评论(0编辑  收藏  举报