Skip to content

Instantly share code, notes, and snippets.

@tagomoris
Created April 24, 2012 06:41
Show Gist options
  • Save tagomoris/2477159 to your computer and use it in GitHub Desktop.
Save tagomoris/2477159 to your computer and use it in GitHub Desktop.
SELECT
date,
category,
COUNT(*) AS c1
FROM (
SELECT date, parse_agent(agent)['category'] AS category
FROM access_logs
WHERE service='blog'
AND (date='20120424' OR date='20120423')
) x
WHERE category='smartphone'
GROUP BY date,category
ORDER BY date,c1 DESC
LIMIT 10
SELECT
date,
parse_agent(agent)['category'],
COUNT(*) AS c1
FROM access_logs
WHERE service='blog'
AND (date='20120424' OR date='20120423')
AND parse_agent(agent)['category']='smartphone'
GROUP BY date,parse_agent(agent)['category']
ORDER BY date,c1 DESC
LIMIT 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment