In SQL I am checking for Null Value. There is presence of Null values in the data set but I am still getting 0 in the output. I have uploaded the data twice to check if the updation is correct or not, but getting same result. In Python Null values are showing but in SQL I am facing issue. Can someone help me what is the potential problem. I am using the following code.
SELECT 'Tenure' as ColumnName, COUNT(*) AS NullCount
FROM ecomm.eccomchurn
WHERE Tenure IS NULL
UNION
SELECT 'WarehouseToHome' as ColumnName, COUNT(*) AS NullCount
FROM ecomm.eccomchurn
WHERE warehousetohome IS NULL
UNION
SELECT 'HourSpendonApp' as ColumnName, COUNT(*) AS NullCount
FROM ecomm.eccomchurn
WHERE hourspendonapp IS NULL
UNION
SELECT 'OrderAmountHikeFromLastYear' as ColumnName, COUNT(*) AS NullCount
FROM ecomm.eccomchurn
WHERE orderamounthikefromlastyear IS NULL
UNION
SELECT 'CouponUsed' as ColumnName, COUNT(*) AS NullCount
FROM ecomm.eccomchurn
WHERE couponused IS NULL
UNION
SELECT 'OrderCount' as ColumnName, COUNT(*) AS NullCount
FROM ecomm.eccomchurn
WHERE ordercount IS NULL
UNION
SELECT 'DaySinceLastOrder' as ColumnName, COUNT(*) AS NullCount
FROM ecomm.eccomchurn
WHERE daysincelastorder IS NULL;
2
Answers
It is possible that the NULL values in your dataset are not actually NULL, but instead contain empty strings or other placeholders. Try modifying your code to check for empty string values as well by using the following syntax:
This will catch any instances where the value is an empty string rather than a true NULL value. Repeat this modification for each of the columns you are checking and see if it resolves the issue with your output showing 0 counts for NULL values.
This should be a comment but its a bit big for the wee box.
How did you determine that? I suspect @Benyamin might be correct.
Your query probably won’t performance very well, consider: