Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

mysql - How to find the list of columns that contain one or more null values in SQL

I am new to the SQL word and came across a problem where I have an IMDb schema with various tables. My query is how do I list all the columns in movie table which have one or more null values.

Movie:
- ID
- Title
- Year
- Date_published
- Duration
- Country
- Worldwide_gross_income
- Languages
- Production_company

Columns containing null values are Languages, Country and Production_company and my query is expected to return this list.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The simplest way is use IS NULL and OR as follows:

Select * 
   From t
  Where Languages is null or country is null
     Or Production_company is null;

Or another way is to use greatest or least function as they return null if any of the argument is null as follows:

Select * 
   From t
  Where greatest(Languages, country, Production_company) is null;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...