1

I'm having a question, I am building up a query.

select top 10 usr.firstname, usr.lastname, count(doc.modifiedBy) as modified_items,
       count(doc.createdDate) as created_items 
from document doc
where doc.active = 't' 
group by usr.firstname, usr.lastname
order by doc.modified_items desc

But I want to sum two counts that are in select so something like this.

select top 10 usr.firstname, usr.lastname, sum(count(doc.modifiedBy), count(doc.createdDate))
4
  • 1
    Dear, which DBMS are you using? Commented Nov 26, 2015 at 10:40
  • 4
    You mean like count(doc.modifiedBy) + count(doc.createdDate)? Commented Nov 26, 2015 at 10:41
  • 2
    @Chris that won't work. Commented Nov 26, 2015 at 10:46
  • Note that if you add them using + then records with both a modified date and a created date will be counted twice. This may or may not be what you want. Commented Nov 26, 2015 at 10:57

1 Answer 1

4

Simple just add + them.

SELECT TOP 10 usr.firstname, usr.lastname, count(doc.modifiedBy) AS modified_items, count(doc.createdDate) AS created_items, (count(doc.modifiedBy)) + (count(doc.createdDate)) AS summed_items
FROM document doc
WHERE doc.active = 't' 
GROUP BY usr.firstname, usr.lastname
ORDER BY doc.modified_items DESC
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.