如何在每个日期获取每个类型的最大 ID

How to get the max ID for every Type every Date

我想为每个日期的每个类型 (Types) 保留最高报告 ID (Report_ID) (日期)

注意:数据列有多个日期,下面只显示01.01.2021。

  SELECT a.*
  FROM Table1 a
  JOIN (
    SELECT Date, MAX(Report_ID) as maxID
    FROM Table1
    GROUP BY Date) b 
  ON a.Report_ID = b.maxID
  WHERE a.Date = '2021-01-01'
  ORDER BY Date desc

您可以使用相关子查询:

select t.*
from t
where t.report_id = (select max(t2.report_id)
                     from t t2
                     where t2.date = t.date and t2.type = t.type
                    );