Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return columns which has NULL or 0 Values in a row

I've a Table with 10 fields. Each field or column contains Integer values.

Now I need only field(s) to be returned which has Null or 0 in the result set.

like image 695
user1549991 Avatar asked Jul 26 '12 22:07

user1549991


People also ask

How do I get columns with NULL values?

You can use df. isnull(). sum() .

What returns the number of rows containing non NULL values in the specified column?

The IS NOT NULL condition is used to return the rows that contain non-NULL values in a column. The following query will retrieve the rows from the Person table which are MiddleName column value is not equal to NULL values.

Which columns can contain NULL values?

NULL values represent missing unknown data. By default, a table column can hold NULL values.


1 Answers

This worked for me. For instance:

Instead of:

where column_name is null or column_name = 0

It would be:

where COALESCE(column_name,0) = 0

Posted by Jon Gabrielson on December 18, 2002

The function 'COALESCE' can simplify working with null values. for example, to treat null as zero, you can use: select COALESCE(colname,0) from table where COALESCE(colname,0) > 1;

like image 158
Quitiweb Avatar answered Oct 17 '22 22:10

Quitiweb