我需要查询按name
进行分组,如果is_new
的一个为1
,则结果值应为1
当前行:
+--------+--------+
| name | is_new |
+--------+--------+
| a | 0 |
| a | 0 |
+--------+--------+
| b | 0 |
| b | 1 |
+--------+--------+
| c | 1 |
| c | 1 |
+--------+--------+
预期查询结果:
+--------+--------+
| name | is_new |
+--------+--------+
| a | 0 |
| b | 1 |
| c | 1 |
+--------+--------+
答案 0 :(得分:6)
SELECT name,MAX(is_new) AS is_new FROM <TABLE> GROUP BY name