Skip to content

Instantly share code, notes, and snippets.

@silv3rm00n
Created May 11, 2012 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silv3rm00n/2659659 to your computer and use it in GitHub Desktop.
Save silv3rm00n/2659659 to your computer and use it in GitHub Desktop.
select
c.referring_domain , SUM(zs.cnt) as zip_searches ,
Count(c.click_id) as visits ,
SUM(ds.conv) as conversions ,
SUM(ds.conv_value) as conv_value
from clicks c
left join
(
SELECT
zy.click_id ,
Count(zy.search_id) AS cnt
FROM zip_searches zy
GROUP BY zy.click_id
)
zs on zs.click_id = c.click_id
left join
(
SELECT
ds2.click_id ,
Count(ds2.sale_id) AS conv ,
SUM(ds2.revenue) AS conv_value
FROM direct_sales ds2
GROUP BY ds2.click_id
)
ds on ds.click_id = c.click_id
WHERE c.source = '7search'
group by c.referring_domain
order by conv_value DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment