示例
示例
SELECT MIN(created_at) AS first_order,
MAX(created_at) AS last_order,
MIN(amount) AS min_amount,
MAX(amount) AS max_amount
FROM orders
WHERE user_id = 42;
SELECT user_id, MAX(amount) AS max_amount
FROM orders
GROUP BY user_id;| NULL | 忽略 |
|---|---|
| 字符串 | 按排序规则比较,可求字典序极值 |
| 索引 | 分组求 MAX 有合适索引时可走松散索引扫描 |