英文:
I am checking null values for Ecommerce Churn dataset in sql but getting 0
问题
在SQL中,我正在检查Null值。数据集中存在Null值,但输出仍然为0。我已经上传了数据两次来检查更新是否正确,但结果仍然相同。在Python中,Null值正常显示,但在SQL中我遇到了问题。有人可以帮我找出潜在的问题吗?我正在使用以下代码。
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;
英文:
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;
答案1
得分: 1
可能您数据集中的NULL值实际上并非NULL,而是包含空字符串或其他占位符。尝试修改您的代码以检查空字符串值,可以使用以下语法:
WHERE Tenure IS NULL OR Tenure = ''
这将捕获值为空字符串而不是真正的NULL值的任何情况。对您正在检查的每一列重复此修改,看看是否解决了输出中显示NULL值计数为0的问题。
英文:
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:
WHERE Tenure IS NULL OR Tenure = ''
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.
答案2
得分: 0
这应该是一条注释,但对于这个小框来说有点长。
> 数据集中存在空值
您是如何确定的?我怀疑 @Benyamin 可能是正确的。
您的查询可能性能不太好,请考虑:
SELECT SUM(IFNULL(Tenure), 1, IF(''=Tenure, 1, 0))
, SUM(IFNULL(warehousetohome), 1, IF(''=warehousetohome, 1, 0))
, SUM(IFNULL(hourspendonapp), 1, IF(''=hourspendonapp, 1, 0))
[...]
, SUM(IFNULL(DaySinceLastOrder), 1, IF(''=DaySinceLastOrder, 1, 0))
FROM ecomm.eccomchurn;
英文:
This should be a comment but its a bit big for the wee box.
> There is presence of Null values in the data set
How did you determine that? I suspect @Benyamin might be correct.
Your query probably won't performance very well, consider:
SELECT SUM(IFNULL(Tenure), 1, IF(''=Tenure, 1, 0))
, SUM(IFNULL(warehousetohome), 1, IF(''=warehousetohome, 1, 0))
, SUM(IFNULL(hourspendonapp), 1, IF(''=hourspendonapp, 1, 0))
[...]
, SUM(IFNULL(DaySinceLastOrder), 1, IF(''=DaySinceLastOrder, 1, 0))
FROM ecomm.eccomchurn;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论