正如标题所示,我想选择用a组成的每组行的第一行GROUP BY.
具体来说,如果我有一个purchases看起来像这样的表:
SELECT * FROM purchases;
Run Code Online (Sandbox Code Playgroud)
我的输出:
id | customer | total ---+----------+------ 1 | Joe | 5 2 | Sally | 3 3 | Joe | 2 4 | Sally | 1
我想查询每个产品id的最大购买量(total)customer.像这样的东西:
SELECT FIRST(id), customer, FIRST(total)
FROM purchases
GROUP BY customer
ORDER BY total DESC;
Run Code Online (Sandbox Code Playgroud)
预期产出:
FIRST(id) | customer | FIRST(total)
----------+----------+-------------
1 | Joe | 5
2 | Sally | 3
将两个哈希值合并到%hash1的最佳方法是什么?我总是知道%hash2和%hash1总是有唯一的密钥.如果可能的话,我也更喜欢一行代码.
$hash1{'1'} = 'red';
$hash1{'2'} = 'blue';
$hash2{'3'} = 'green';
$hash2{'4'} = 'yellow';
Run Code Online (Sandbox Code Playgroud)