Conditional GROUP BY result
I need the query to group by name
and, if开发者_高级运维 one of the is_new
is 1
, the resulting value should be 1
.
Current rows:
+--------+--------+
| name | is_new |
+--------+--------+
| a | 0 |
| a | 0 |
+--------+--------+
| b | 0 |
| b | 1 |
+--------+--------+
| c | 1 |
| c | 1 |
+--------+--------+
Expected query result:
+--------+--------+
| name | is_new |
+--------+--------+
| a | 0 |
| b | 1 |
| c | 1 |
+--------+--------+
SELECT name,MAX(is_new) AS is_new FROM <TABLE> GROUP BY name
精彩评论