【发布时间】:2020-10-24 01:45:04
【问题描述】:
我有一个很好的递归 WITH 子句:
WITH RECURSIVE split(seq, word, str) AS (
SELECT 0, null, replace('name+one+two+three.jpg', '.jpg', '+')
UNION ALL SELECT
seq+1,
substr(str, 0, instr(str, '+')),
substr(str, instr(str, '+')+1)
FROM split WHERE str != ''
) SELECT word FROM split where seq>1
输出是:
one
two
three
现在,我怎样才能重用这个子句,应用SELECT name from Images 代替那个常量字符串'name+one+two+three.jpg'?
目标是提取可以在整个图像名称集中找到的所有唯一“+后缀”字符串。例如,这是示例数据:
DROP TABLE IF EXISTS ImagesTemp;
CREATE TEMP TABLE ImagesTemp (name );
INSERT INTO ImagesTemp (name)
VALUES
('IMG_0403+newport+malboro+kool.jpg'),
('IMG_0404+camel+newport.JPG'),
('IMG_0405+dunhill+doral+malboro.png');
SELECT * from ImagesTemp
预期的输出是:
word count
malboro 2
newport 2
kool 1
dunhill 1
doral 1
camel 1
【问题讨论】:
-
发布样本数据和预期结果以澄清。
标签: sql sqlite common-table-expression recursive-query