如何选择仅包含NULL值的分组行? [英] How to select grouped rows with only NULL values?

查看:64
本文介绍了如何选择仅包含NULL值的分组行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个类似

task_id | state
--------+------------ 
   1    |  NULL
--------+------------
   1    |  RESOLVED
--------+------------
   2    |  NULL
--------+------------
   2    |  NULL

如何通过task_id获得分组的行,其状态仅为NULL.在这种情况下,只有具有task_id 2的行.

How can I get grouped rows via task_id which state is only NULL. In this case only rows with task_id 2.

推荐答案

执行GROUP BY,使用HAVING返回仅具有空状态的task_id.

Do a GROUP BY, use HAVING to return task_id having only null states.

select task_id
from tablename
group by task_id
having max(state) is null

这篇关于如何选择仅包含NULL值的分组行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆