MySQL:如何分别对列进行计数?
通常我对 SQL 查询非常有信心,但是这个让我摸不着头脑。我觉得这应该是一个快速解决方案,但我只是没有看到它。
我正在尝试在一个查询中对同一个表上的多个值进行计数。
不要介意“0000000000000000”,它只是代表一个空字节数组。
有没有一种简单的方法来组合这些查询?
SELECT COUNT(ssn)
FROM patients
WHERE ssn="0000000000000000";
SELECT COUNT(firstname)
FROM patients
WHERE firstname="0000000000000000"
SELECT COUNT(lastname)
FROM patients
WHERE lastname="0000000000000000"
etc...
Usually I feel pretty confident with SQL queries, however this one has me scratching my head. I feel like this -should- be a quick fix, but I'm just not seeing it.
I'm trying to do a count on multiple values on the same table, in one query.
Don't mind the "0000000000000000" it's just representing an empty byte array.
Is there an easy way to combine these queries?
SELECT COUNT(ssn)
FROM patients
WHERE ssn="0000000000000000";
SELECT COUNT(firstname)
FROM patients
WHERE firstname="0000000000000000"
SELECT COUNT(lastname)
FROM patients
WHERE lastname="0000000000000000"
etc...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以做这样的事情 -
You can do something like this -
尝试使用 UNION
Try with UNION
我想这会起作用吗?
I guess this would work?