【发布时间】:2016-11-11 00:17:37
【问题描述】:
我想选择每个 new_threads 组的第二个响应列值,如果它是一组 1 行,则值为零。
new_treads|response
------------------
1 | 0
1 | 1
2 | 0
2 | 0
2 | 1
... | ...
9 | 0
9 | 1
9 | 0
10 | 0
输出是:
new_treads|response
------------------
1 | 1
2 | 0
... | ...
9 | 1
10 | 0
到目前为止,我了解如何使用 MIN 获得第一个,但我需要第二个
SELECT
thread,
min(response)
FROM messages
GROUP BY thread;
我想使用 GROUP BY,因为我也将 GROUP BY 用于其他 SELECT
谢谢!
【问题讨论】: