-- 从最新的数据中取出 制作中的数据
SELECT id,user_id,material_id,status FROM (
-- https://blog.csdn.net/qq_37111953/article/details/80916820
-- 取出每个用户最新的一条用户物料数据
select a.id,a.user_id,a.material_id,a.status
from (
select * from xxxxxx
where activity_id = n and ds = 20100622
) a
left join (
select * from xxxxxx
where activity_id = n and ds = 20100622
) b
on a.user_id=b.user_id and a.gmt_create<b.gmt_create
group by a.id,a.user_id,a.material_id,a.status
having count(b.id)<1
-- 取出每个用户最新的一条用户物料数据
)as last_record_all
where status = 1
-- 从最新的数据中取出 制作中的数据