开发者

Conditional GROUP BY result

开发者 https://www.devze.com 2023-03-22 20:52 出处:网络
I need the query to group by name and, if开发者_高级运维 one of the is_new is 1, the resulting value should be 1.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消