67. Split CSV Tags Into Rows
HardRecursive CTEsRecursive CTEString SplitSUBSTRINSTR
Without a split function, you tokenize a delimited string by recursion: peel off the text before the first comma as the current element, keep the remainder, and recurse until the remainder is empty. A position counter numbers the elements.
The posts table stores a comma-separated tags string per post.
Task: for post id 1, split its tags ('red,green,blue,yellow') into one row per tag, with a 1-based position.
Return columns position, tag, ordered by position ascending.
Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…
This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases — 5test cases in all. A sloppy query that only fits the example won't pass.
SQL· SQLite · runs in your browser
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.