假设我有下表记录:
Id | machine | manual |
-------------------------------------
1 | 1 | false |
2 | 2 | false |
3 | 3 | false |
4 | 4 | false |
5 | 1 | true |
我想根据机器列检索一个不同的表,但是当涉及到在 manual: false 或 true 之间“选择”时,true 胜过 false。
Id | machine | manual |
-------------------------------------
5 | 1 | true |
2 | 2 | false |
3 | 3 | false |
4 | 4 | false |
我该怎么做?
最佳答案
SELECT x.*
FROM my_table x
JOIN
( SELECT machine,MAX(manual) manual FROM my_table GROUP BY machine ) y
ON y.machine = x.machine
AND y.manual = x.manual;
关于mysql group by 基于另一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41446291/