gpt4 book ai didi

mysql - 计算列中唯一单词的数量

转载 作者:行者123 更新时间:2023-11-29 06:04:43 25 4
gpt4 key购买 nike

<分区>

我有一个类似这样的表

quantity | part_numbers
1 | T101; T103
3 | T103; T102
1 | T101; T102; T103

我正在尝试编写一个会返回的脚本

part_number | quantity
T101 | 2
T102 | 4
T103 | 5

我发现这个脚本有效但没有考虑数量

SELECT SUM(total_count) as total, value
FROM (

SELECT (count(*)) AS total_count, REPLACE(REPLACE(REPLACE(x.value,'?',''),'.',''),'!','') as value
FROM (
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(t.part_numbers, ' ', n.n), ' ', -1) value
FROM order_items t CROSS JOIN
(
SELECT a.N + b.N * 10 + 1 n
FROM
(SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a
,(SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) b
ORDER BY n
) n
WHERE n.n <= 1 + (LENGTH(t.part_numbers) - LENGTH(REPLACE(t.part_numbers, ' ', '')))
ORDER BY value

) AS x
GROUP BY x.value

) AS y
GROUP BY value
order by total desc

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com