MySql:计算单词在单元格中出现的次数,并将数字放在单词旁边,

ny6fqffe  于 12个月前  发布在  Mysql
关注(0)|答案(1)|浏览(181)

我需要table有:
accountprefix需要包含“Oil”(#),用于计算“Oil”在该单元格中出现的次数

SELECT
  jurisdiction,
  Replace(REPLACE(REPLACE(GROUP_CONCAT(DISTINCT LEFT(fileno, 1)ORDER BY fileno DESC SEPARATOR ', '),'O','Oil')'M','Mobile'),'R','Real')AS accountprefix
From
  table.tester
WHERE
  statuscode = 'A'
  AND builddateid = '2023'
GROUP BY jurisdiction;

字符串
accountprefix需要包含“Oil”(#),用于计算“Oil”在该单元格中出现的次数

7d7tgy0s

7d7tgy0s1#

尝试以下操作,我修改了查询,通过将'O'替换为'Oil(count)'来计数和显示'Oil'在accountprefix中出现的次数,其中计数表示每个jurisdictionfileno列中出现'O'的次数。

SELECT
  jurisdiction,
  REPLACE(
    REPLACE(
      REPLACE(
        GROUP_CONCAT(DISTINCT LEFT(fileno, 1) ORDER BY fileno DESC SEPARATOR ', '),
        'O', CONCAT('Oil (', COUNT(CASE WHEN LEFT(fileno, 1) = 'O' THEN 1 END), ')')
      ),
      'M', 'Mobile'
    ),
    'R', 'Real'
  ) AS accountprefix
FROM
  table.tester
WHERE
  statuscode = 'A'
  AND builddateid = '2023'
GROUP BY jurisdiction;

字符串

相关问题