我有三列名称:
projectNo| process | procLeader | procCheker | Stuff |
----------+---------+------------+-------------+---------------+
16090001 | ANM | ben | barry | bob, bart, bok|
16090001 | BLD | anton | kirill | kart, ali |
我想要的是计算procLeader,procChecker,填充分配给projectNo的列。我设法使用查询计算每列:
SELECT
COUNT(procLeader) AS `ld`,
COUNT(procChecker) AS `ch`,
SUM((LENGTH(stuff) - LENGTH(REPLACE(stuff,",","")) + 1)) AS `st`
FROM `process`
WHERE projectNo=16090001;
我得到了
ld| ch | st |
---+----+----+
2| 2| 5|
我需要像'总'表
这样的东西我如何总结这些价值观?或者可能使用其他方法?
答案 0 :(得分:3)
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
如果您有任何疑虑或问题,请告知我们。
答案 1 :(得分:1)
使用以下查询,它有效:
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
输出:
Id - ch - st - Total
2 - 2 - 5 - 9
答案 2 :(得分:0)
不确定我理解问题,但如果你想计算字符,你是否尝试过char_length和concat?
SELECT char_length(concat(procleader, proccheker, REPLACE(stuff,',',''))) FROM process WHERE projectNo=16090001