Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a table that has the following columns: year, city, country, avg_temp.
I am trying to write a query that extracts the data into a CSV, but I want the fields with no input to show NULL for avg_temp.
SELECT IF(columnName IS NULL, 'NULL', columnName) as columnName FROM table
You can check in the select with
CASE WHEN avg_temp IS NULL THEN 'NULL' ELSE avg_temp END AS avg_temp
Or with if
IF (avg_temp IS NULL, 'NULL', avg_temp) AS avg_temp
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
SELECT IF(columnName IS NULL, 'NULL', columnName) as columnName FROM table