Yevgeniy Bagackiy Yevgeniy Bagackiy - 2 months ago 11
MySQL Question

How to count sum of three columns MySql

I have three columns with names:

projectNo| process | procLeader | procCheker | Stuff |
----------+---------+------------+-------------+---------------+
16090001 | ANM | ben | barry | bob, bart, bok|
16090001 | BLD | anton | kirill | kart, ali |


What I want to is to count procLeader, procChecker, stuff columns assigned to projectNo. I managed to count each column by using query:

SELECT
COUNT(procLeader) AS `ld`,
COUNT(procChecker) AS `ch`,
SUM((LENGTH(stuff) - LENGTH(REPLACE(stuff,",","")) + 1)) AS `st`
FROM `process`
WHERE projectNo=16090001;


I get

ld| ch | st |
---+----+----+
2| 2| 5|


I need something like 'total' table

How I can sum this values? or maybe use another method?

Answer
SELECT 
COUNT(procLeader) AS `ld`, COUNT(procCheker) AS `ch`, 
SUM((LENGTH(stuff) - LENGTH(REPLACE(stuff,",","")) + 1)) AS `st` ,
(
   COUNT(procLeader) + 
    COUNT(procCheker) +
    SUM((LENGTH(stuff) - LENGTH(REPLACE(stuff,",","")) + 1)) 
 ) As `Total` 
 FROM `process` WHERE projectNo=16090001

Please let us know if you have any concerns or que.