Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Count all rows and add a certain int from column of each result row into overall count

I have a table consisting of columns tblEventID, isSafeSlot, plusOnes. I want to retrieve the number of rows where tblEventID is equal to X and isSafeSlot is equal to true, and if both are true, also check the column plusOnes for that one row. This column will hold an int from 0 to 99. I need to add those numbers also into the count.

So say we have this table:

tblEventID / isSafeSlot / plusOnes
100 / true / 0
100 / true / 53
100 / false / 0 
101 / true / 99 

And I am giving it tblEventID 100, the count result should be 55 (two rows making the count 2, plus one row has the number 53 stored under plusOnes, result 55)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I make this inside one query?

>Solution :

SELECT COUNT(*) + SUM(plusOnes) AS total
FROM `say_we_have_this_table`
WHERE tblEventId = 100
 AND isSafeSlot = true;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading