Find all those columns which have only null values, in a MySQL table

后端 未结 6 1418
太阳男子
太阳男子 2020-12-08 07:43

The situation is as follows:

I have a substantial number of tables, with each a substantial number of columns. I need to deal with this old and to-be-deprecated data

6条回答
  •  春和景丽
    2020-12-08 08:46

    I think you can do this with GROUP_CONCAT and GROUP BY:

    select length(replace(GROUP_CONCAT(my_col), ',', ''))
    from my_table
    group by my_col
    

    (untested)

    EDIT: the docs don't seem to state that GROUP_CONCAT needs a corresponding GROUP BY, so try this:

    select 
        length(replace(GROUP_CONCAT(col_a), ',', '')) as len_a
        , length(replace(GROUP_CONCAT(col_b), ',', '')) as len_b
        , length(replace(GROUP_CONCAT(col_c), ',', '')) as Len_c
    from my_table
    

提交回复
热议问题