How to detect and remove a column that contains only null values?

后端 未结 6 2424
说谎
说谎 2020-12-30 14:50

In my table table1 there are 6 columns Locations,a,b,c,d,e.

Locations [a]   [b]   [c]  [d]   [e]

[1]       10.00 Null  Null 20.00 Null

[2]         


        
6条回答
  •  独厮守ぢ
    2020-12-30 15:09

    How to detect whether a given column has only the NULL value:

    SELECT 1  -- no GROUP BY therefore use a literal
      FROM Locations
    HAVING COUNT(a) = 0 
           AND COUNT(*) > 0;
    

    The resultset will either consist of zero rows (column a has a non-NULL value) or one row (column a has only the NULL value). FWIW this code is Standard SQL-92.

提交回复
热议问题