How to select grouped rows with only NULL values?

前端 未结 4 1118
一生所求
一生所求 2021-01-24 16:15

If I have a table like

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


        
相关标签:
4条回答
  • 2021-01-24 17:06

    As COUNT function ignores NULL in case a specific column is assigned, you can use group by, count and having as below.

    SELECT task_id
    FROM t1
    GROUP BY task_id
    HAVING count(STATE) = 0;
    

    DEMO

    0 讨论(0)
  • 2021-01-24 17:17

    Try this -

    SELECT task_id
    FROM YOUR_TABLE
    WHERE state NOT IN (SELECT task_id
                        FROM YOUR_TABLE
                        WHERE task_id IS NOT NULL)
    
    0 讨论(0)
  • 2021-01-24 17:18

    here is my approach :

        Select  * from yourTable where state is null and task_id not in 
        (select task_id from yourTable y where state is not null )
    
    0 讨论(0)
  • 2021-01-24 17:19

    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
    
    0 讨论(0)
提交回复
热议问题