我在Google表格中有一张数据表,我需要从中提取最大值以及多个组的其他对应值。
例如,这是工作表的外观的表示形式:
+---------+--------+-----------+
| Team | Player | Home Runs |
+---------+--------+-----------+
| Mets | John | 9 |
+---------+--------+-----------+
| Yankees | Edward | 3 |
+---------+--------+-----------+
| Red Sox | Mike | 1 |
+---------+--------+-----------+
| Mets | Joe | 2 |
+---------+--------+-----------+
| Mets | Geoff | 4 |
+---------+--------+-----------+
| Yankees | Max | 7 |
+---------+--------+-----------+
| Yankees | Danny | 5 |
+---------+--------+-----------+
| Red Sox | Clint | 0 |
+---------+--------+-----------+
| Red Sox | Clyde | 8 |
+---------+--------+-----------+
我想要的结果集:
+---------+--------+-----------+
| Team | Player | Home Runs |
+---------+--------+-----------+
| Mets | John | 9 |
+---------+--------+-----------+
| Yankees | Max | 7 |
+---------+--------+-----------+
| Red Sox | Clyde | 8 |
+---------+--------+-----------+
如果我正在编写SQL查询,我会尝试使用row_number
窗口函数按团队对球员进行排序,然后仅选择每个团队的最高价值。我知道在Sheets中有一个Query函数,但是我不确定是否有写窗口函数或在该函数中使用row_number
的方法。也许这里还有另一个SQL式的方法,它也不需要窗口函数。预先感谢。
答案 0 :(得分:1)
您可以使用两个公式:
=QUERY(A2:C10, "select * order by A,C desc")
//highlighted cell
和
=FILTER(G2:I12,G2:G12<>G1:G11)
在一个单元格中组合为一个公式:
=FILTER(QUERY(A1:C11,"select * order by A,C"),{QUERY(A1:C10,"select A order by A,C");""}<>{"";QUERY(A1:C10,"select A order by A,C")})
答案 1 :(得分:0)
另一种方法是对排序表上的唯一组名使用vlookup。像这样:
=ArrayFormula(iferror(vlookup(unique(A:A), sort(A:C, 3, 0), {1, 2, 3}, 0)))