|
发表于 2024-11-14 14:37:26
|
显示全部楼层
河北省保定市
WITH RECURSIVE split_segments AS (
-- Step 1: 初始行分割第一段
SELECT
id,
SUBSTRING_INDEX(col, '|', 1) AS segment,
SUBSTRING_INDEX(col, '|', -1) AS remaining
FROM your_table
UNION ALL
-- Step 2: 递归地拆分剩余段落
SELECT
id,
SUBSTRING_INDEX(remaining, '|', 1) AS segment,
SUBSTRING_INDEX(remaining, '|', -1) AS remaining
FROM split_segments
WHERE remaining LIKE '%|%'
),
-- Step 3: 提取每个段中 E 和 F 中间的数字(名称为“名称1”)
extract_values AS (
SELECT
id,
segment,
CAST(REGEXP_SUBSTR(segment, 'E ([0-9]+) F') AS UNSIGNED) AS e_value
FROM split_segments
WHERE segment LIKE '%A 名称1%'
)
-- Step 4: 求和
SELECT
id,
SUM(e_value) AS total_e_value
FROM extract_values
GROUP BY id;
|
|