How to count NULL values in MySQL?

前端 未结 7 1175
猫巷女王i
猫巷女王i 2021-02-04 03:56

I want to know how can i find all the values that are NULL in the MySQL database for example I\'m trying to display all the users who don\'t have an average yet.

Here i

7条回答
  •  花落未央
    2021-02-04 04:50

    A more generic version (that doesn't depend on the where clause and hence limits your overall results):

    SELECT 
        SUM(CASE WHEN average IS NULL THEN 1 ELSE 0 END) As null_num, 
        SUM(CASE WHEN average IS NOT NULL THEN 1 ELSE 0 END) AS not_null_num
    FROM users
    

    It's not better then the specific queries presented by other answers here, but it can be used in situations where using a limiting where clause is impractical (due to other information being needed)...

提交回复
热议问题