gpt4 book ai didi

mysql - 如何计算具有空白值或 0 值的列数

转载 作者:太空宇宙 更新时间:2023-11-03 11:49:55 24 4
gpt4 key购买 nike

我是 mysql 的新手。请帮助我解决以下需求。

表格示例:-

--------+-----------+-----------+--------+---------+
Id. | fname | lname | qid1 | qid2 |
--------+-----------+-----------+--------+---------+
1 | atul. | | 0 | 0 |
--------+-----------+-----------+--------+---------+-

我希望答案为第一个 ID 的“3”,因为“lname”为空且“qid1”、“qid2”为 0。

最佳答案

您可以在大多数数据库中使用case;然而,MySQL 提供了一个快捷方式,您可以在其中添加 bool 表达式:

select t.*,
((fname is null or fname = '') +
(lname is null or lname = '') +
(qid1 is null or qid1 = '') +
(qid2 is null or qid2 = '')
) as numBlankOrNull
from t;

关于mysql - 如何计算具有空白值或 0 值的列数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36130426/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com