如何从这些数组字符串中获取ID?
E.g:
a:5:{i:0;i:47464;i:1;i:47571;i:2;i:47572;i:3;i:47693;i:4;i:47694;}
a:8:{i:0;i:48584;i:1;i:49521;i:2;i:49542;i:3;i:49799;i:4;i:49967;i:5;i:50127;i:6;i:50268;i:7;i:50270;}
a:3:{i:0;i:38752;i:1;i:38753;i:2;i:38892;}
将单个Id分开:
id
------
47464
47571
47572
47693
47694
48584
49521
...
...
答案 0 :(得分:0)
一种方法(假设所有id都大于100,如果你只是相应地更改了HAVING子句,你在一行中不会超过100)是一个临时数字表,它保存1-999然后加入该表...如果您在一行中有超过1000个ID,那么您还有其他问题需要处理。
CREATE TEMPORARY TABLE digits AS
SELECT
SEQ.SeqValue
FROM
( SELECT (HUNDREDS.SeqValue + TENS.SeqValue + ONES.SeqValue) SeqValue
FROM(SELECT 0 SeqValue 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) ONES
CROSS JOIN(SELECT 0 SeqValue UNION ALL SELECT 10 UNION ALL SELECT 20 UNION ALL SELECT 30 UNION ALL SELECT 40 UNION ALL SELECT 50 UNION ALL SELECT 60 UNION ALL SELECT 70 UNION ALL SELECT 80 UNION ALL SELECT 90) TENS
CROSS JOIN(SELECT 0 SeqValue UNION ALL SELECT 100 UNION ALL SELECT 200 UNION ALL SELECT 300 UNION ALL SELECT 400 UNION ALL SELECT 500 UNION ALL SELECT 600 UNION ALL SELECT 700 UNION ALL SELECT 800 UNION ALL SELECT 900) HUNDREDS
) SEQ
制作数字表后使用此查询清除随机内容
SELECT
REPLACE(REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(huge_str, 'i:', n.digit+1), 'i:', -1), ';', ''), '}', '') cleaned_str
FROM (SELECT SUBSTRING(huge_str, 6) AS huge_str FROM mashed_shit) t
JOIN(SELECT seqvalue AS digit FROM digits) n
ON LENGTH(REPLACE(huge_str, 'i:' , '')) <= LENGTH(huge_str)-n.digit
GROUP BY cleaned_str
HAVING cleaned_str >= 10
ORDER BY n.digit