Reputation: 974
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?
Upvotes: 1
Views: 312
Reputation: 3149
Use the following query and it worked:
SELECT
COUNT(procLeader) AS `ld`, COUNT(procChecker) AS `ch`,
SUM((LENGTH(stuff) - LENGTH(REPLACE(stuff,",","")) + 1)) AS `st` ,
(
COUNT(procLeader) +
COUNT(procChecker) +
SUM((LENGTH(stuff) - LENGTH(REPLACE(stuff,",","")) + 1))
) As `Total`
FROM `process` WHERE projectNo = 16090001
Output:
Id - ch - st - Total
2 - 2 - 5 - 9
Upvotes: 1
Reputation: 3106
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.
Upvotes: 3
Reputation: 41
not sure I understand question, but if you want to count characters, did you try char_length and concat ?
SELECT char_length(concat(procleader, proccheker, REPLACE(stuff,',',''))) FROM process WHERE projectNo=16090001
Upvotes: 0