sql >> データベース >  >> RDS >> Mysql

MySQLテーブルのEMPTYまたはNULL列の数を検索します

    次のような結果を得ることが目的の場合:

    col       emp    
    ------    ------    
    FName        15  
    LName         2  
    Age          22 
    

    ..使用:

    SELECT 'FName' AS col, SUM(CASE FName IS NULL || FName='' THEN 1 ELSE 0 END) as emp FROM MyTable
    UNION
    SELECT 'LName' AS col, SUM(CASE LName IS NULL || LName='' THEN 1 ELSE 0 END) as emp FROM MyTable
    UNION
    SELECT 'Age' AS col, SUM(CASE Age IS NULL || Age='' THEN 1 ELSE 0 END) as emp FROM MyTable
    

    ...または:

    SELECT SUM(CASE t.fname IS NULL OR t.fname = '' THEN 1 ELSE 0 END) AS fname_count,
           SUM(CASE t.lname IS NULL OR t.lname = '' THEN 1 ELSE 0 END) AS lname_count,
           SUM(CASE t.age IS NULL OR t.age = '' THEN 1 ELSE 0 END) AS age_count
      FROM MYTABLE t
    


    1. T-SQL分割文字列

    2. Laravel PDOException SQLSTATE[HY000][1049]不明なデータベース'forge'

    3. 左参加は内部参加を上回っていますか?

    4. 続編:複数のwhere句