简体   繁体   English

SQL如何对COUNT检索的字段求和?

[英]SQL How do you SUM the fields retrieved by COUNT?

This is what I tried, but it didnt work. 这是我尝试过的,但是没有用。

Select customer_id, sum(count (contact_id), count (call_id))
from contacts
limit 10

If you are trying to add together the count of contact_ids and call_ids you can simply use + between the two fields 如果您尝试将contact_ids和call_ids的数量加在一起,则可以在两个字段之间简单地使用+

Select customer_id, count (contact_id)+count (call_id)
from contacts
limit 10
Select customer_id, count (contact_id) + count (call_id)
from contacts
limit 10

you may need a GROUP BY clause unless your db adds one for you (mysql in certain configurations) 您可能需要GROUP BY子句,除非您的数据库为您添加了一个子句(在某些配置中为mysql)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM