按 SQL 中的 2 个不同值分组并过滤
Group by and filter on 2 Distinct values in SQL
我有table T1
ID Size
A 1
A 2
A 3
B 3
B 4
C 2
C 4
我想按ID分组,过滤每个ID的最小尺寸
期望的结果:
A 1
B 3
C 2
我试过这样做:
SELECT ID, Size
FROM T1
WHERE ID IN (SELECT DISTINCT ID FROM T1)
您需要一个基本的 GROUP BY
查询:
SELECT ID, MIN(Size) AS Size
FROM T1
GROUP BY ID;
SELECT T1.id, MIN(T1.SIZE) AS MinimumSize FROM T1 GROUP BY T1.ID
也许你能找到你的解决方案。
我有table T1
ID Size
A 1
A 2
A 3
B 3
B 4
C 2
C 4
我想按ID分组,过滤每个ID的最小尺寸
期望的结果:
A 1
B 3
C 2
我试过这样做:
SELECT ID, Size
FROM T1
WHERE ID IN (SELECT DISTINCT ID FROM T1)
您需要一个基本的 GROUP BY
查询:
SELECT ID, MIN(Size) AS Size
FROM T1
GROUP BY ID;
SELECT T1.id, MIN(T1.SIZE) AS MinimumSize FROM T1 GROUP BY T1.ID
也许你能找到你的解决方案。