【问题标题】:Display one entry of each type SQL Query显示每种类型 SQL Query 的一个条目
【发布时间】:2022-07-06 18:53:52
【问题描述】:

我必须从下面提到的表格中获取数据。如您所见,Entry Type 有两种类型:完整的数据备份和日志备份。我只需要根据时间戳查询其中任何一个的最新成功和错误的一个条目。

所以我需要的输出是:

Success   complete data backup   2022-07-11 15:27:10(this is the latest entry of this type.)
Error     complete data backup   2022-07-06 15:28:37(this is the latest entry of this type.)
Success   log backup             2022-07-29 15:27:16(this is the latest entry of this type.)
Error     log backup             2022-07-28 15:28:29(this is the latest entry of this type.)

到目前为止我已经尝试过了

"SELECT ENTRY_TYPE_NAME, Status, TimeStamp from M_BACKUP_CATALOG where Status='Success' OR Status='Error' order by TimeStamp DESC"

但它会按降序显示所有条目。而我只想要我表中的两个 entry_type_name(完整数据备份和日志备份)的一个成功和一个错误。

【问题讨论】:

    标签: sql


    【解决方案1】:

    您必须结合 Max 函数使用 group by。

    SELECT ENTRY_TYPE_NAME, Status, MAX(TimeStamp) as TimeStamp from M_BACKUP_CATALOG Group by ENTRY_TYPE_NAME, Status
    

    【讨论】:

      猜你喜欢
      • 2022-07-25
      • 1970-01-01
      • 2020-03-24
      • 2021-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多