【问题标题】:Condition the selection with respect to 2 columns to return max value in one column for duplicate entries in another column调整相对于 2 列的选择以在一列中返回最大值以用于另一列中的重复条目
【发布时间】:2021-03-08 22:00:31
【问题描述】:
SELECT *
FROM table
WHERE COL1 IN (1, 2, 3) AND COL2 IN (7, 8, 9)
COL1 COL2
1 8
2 ​ 7
2 ​ 8
2 ​ 9
3 ​ 7
3 8

我希望结果是每个 COL1 条目在 COL2 中的最大条目,如下所示。

COL1 COL2
1 8
2 ​ 9
3 8

【问题讨论】:

    标签: sql sql-server select


    【解决方案1】:

    不就是这样

    select col1, Max(col2)
    from table
    where col1 in (1, 2, 3) and col2 in (7, 8, 9)
    group by col1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-12
      • 2021-06-10
      • 2023-04-06
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多