mysql从每个分组中取特定条件行的全部内容

取每个task_id分组中更新日期最新的一行
采用join的方式完成

select  a.task_id,
        a.theme_id,
        a.time_unix
from    table_xxx a
join    (
            select  task_id,
                    max(time_unix) as max_time
            from    table_xxx
            where   date <= '${date}'
            and     date >= '${date}' - 3
            and     theme_id > 0
            group by
                    task_id
        ) b
on      date <= '${date}'
and     date >= '${date}' -3
and     a.task_id = b.task_id
and     a.time_unix = b.max_time
) t2

你可能感兴趣的:(mysql,mysql,数据库)