Skip to content

Instantly share code, notes, and snippets.

@nuria
Created November 2, 2016 19:44
Show Gist options
  • Select an option

  • Save nuria/9d4daaac2e910d02917e0fe740159ef1 to your computer and use it in GitHub Desktop.

Select an option

Save nuria/9d4daaac2e910d02917e0fe740159ef1 to your computer and use it in GitHub Desktop.
hive group and count example
SELECT
month,
day,
SUM(CASE WHEN (user_agent LIKE '%iPhone%') THEN 1 ELSE 0 END) AS iphone,
SUM(CASE WHEN (user_agent LIKE '%iOS%') THEN 1 ELSE 0 END) AS iOS
FROM wmf.webrequest
WHERE webrequest_source = 'text'
AND year = 2016
AND month IN (9, 10)
AND (user_agent like '%iOS%' OR user_agent like '%iPhone%')
AND (user_agent like '%Wikipedia/5.0%' OR user_agent like '%WikipediaApp%')
GROUP BY
month,
day
ORDER BY
month,
day
LIMIT 1000;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment