Skip to content

Instantly share code, notes, and snippets.

@simonw
Last active February 15, 2022 15:22
Show Gist options
  • Select an option

  • Save simonw/e814b04b9ea57b875e94d6a737b88b5e to your computer and use it in GitHub Desktop.

Select an option

Save simonw/e814b04b9ea57b875e94d6a737b88b5e to your computer and use it in GitHub Desktop.
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