Last active
February 15, 2022 15:22
-
-
Save simonw/e814b04b9ea57b875e94d6a737b88b5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with snippets as ( | |
| select | |
| substr(body, instr(body, 'refcode=') + 8, 128) as snippet | |
| from | |
| emails | |
| where | |
| body LIKE '%refcode%' | |
| ), | |
| refcodes as ( | |
| select | |
| snippet, | |
| substr( | |
| snippet, | |
| 0, | |
| min( | |
| case | |
| when instr(snippet, '&') > 0 then instr(snippet, '&') | |
| else 128 | |
| end, | |
| case | |
| when instr(snippet, ']') > 0 then instr(snippet, ']') | |
| else 128 | |
| end, | |
| case | |
| when instr(snippet, ' ') > 0 then instr(snippet, ' ') | |
| else 128 | |
| end, | |
| case | |
| when instr(snippet, '.') > 0 then instr(snippet, '.') | |
| else 128 | |
| end | |
| ) | |
| ) as refcode | |
| from | |
| snippets | |
| ) | |
| select | |
| refcode, | |
| count(*) as n | |
| from | |
| refcodes | |
| group by | |
| refcode | |
| order by | |
| n desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment