MySQL 检查空值或空值
MySQL check blank or null values
我需要帮助验证 mysql 中的空值或空值
我尝试在我的案例中使用这种方式,但没有用:
SELECT
CASE
WHEN account_type IS NULL THEN 'Uninformed'
WHEN account_type = '' THEN 'Empty '
END as Type,
COUNT(accounts.id) AS Total
FROM
accounts
有谁知道我该如何解决这个问题?
SELECT
CASE WHEN account_type IS NULL THEN 'Uninformed'
WHEN account_type = '' THEN 'Empty '
END as Type,
COUNT(accounts.id) AS Total
FROM accounts
group by account_type
您缺少 group by
子句。
您的查询是正确的。最后你需要添加 group by account_type;
.
查询应该是这样的。
SELECT
CASE WHEN account_type IS NULL THEN 'Uninformed'
WHEN account_type = '' THEN 'Empty '
END AS Type,
COUNT(accounts.id) AS Total
FROM accounts
GROUP BY account_type
另一种不使用 case 语句编写相同查询的巧妙方法类似于……
SELECT ISNULL(NULLIF(ISNULL(account_type , 'Uninformed'),''),'Empty') AS Type
,COUNT(accounts.id) AS Total
FROM accounts
GROUP BY ISNULL(NULLIF(ISNULL(account_type , 'Uninformed'),''),'Empty')
我需要帮助验证 mysql 中的空值或空值 我尝试在我的案例中使用这种方式,但没有用:
SELECT
CASE
WHEN account_type IS NULL THEN 'Uninformed'
WHEN account_type = '' THEN 'Empty '
END as Type,
COUNT(accounts.id) AS Total
FROM
accounts
有谁知道我该如何解决这个问题?
SELECT
CASE WHEN account_type IS NULL THEN 'Uninformed'
WHEN account_type = '' THEN 'Empty '
END as Type,
COUNT(accounts.id) AS Total
FROM accounts
group by account_type
您缺少 group by
子句。
您的查询是正确的。最后你需要添加 group by account_type;
.
查询应该是这样的。
SELECT
CASE WHEN account_type IS NULL THEN 'Uninformed'
WHEN account_type = '' THEN 'Empty '
END AS Type,
COUNT(accounts.id) AS Total
FROM accounts
GROUP BY account_type
另一种不使用 case 语句编写相同查询的巧妙方法类似于……
SELECT ISNULL(NULLIF(ISNULL(account_type , 'Uninformed'),''),'Empty') AS Type
,COUNT(accounts.id) AS Total
FROM accounts
GROUP BY ISNULL(NULLIF(ISNULL(account_type , 'Uninformed'),''),'Empty')