简体   繁体   中英

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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