Skip to content

Instantly share code, notes, and snippets.

@selenamarie
Last active December 21, 2015 20:19
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 selenamarie/bdd2d0dea6e00944475a to your computer and use it in GitHub Desktop.
Save selenamarie/bdd2d0dea6e00944475a to your computer and use it in GitHub Desktop.
with cte as (
select
address_id
, json_object_field_text(raw_crash, 'Android_Version') as android_version
, json_object_field_text(raw_crash, 'Android_Model') as android_model
from
reports_clean_20131007 clean
JOIN raw_crashes_20131007 rc ON rc.uuid = clean.uuid::uuid
WHERE
json_object_field_text(raw_crash, 'Android_Version') is not null
and json_object_field_text(raw_crash, 'Android_Model') is not null
), total_count as (
select
count(*)
from cte
), glob_count as (
select
count(*)
, android_version
, android_model
from cte
group by android_version, android_model
), _0x0_count as (
select
count(*)
, android_version
, android_model
from cte
where address_id = 1513596
group by android_version, android_model
)
select
_0x0_count.count as _0x0_count
, _0x0_count.android_version
, _0x0_count.android_model
, glob_count.count as device_model_count
, total_count.count as total_count
FROM _0x0_count
LEFT OUTER JOIN glob_count USING (android_version, android_model)
CROSS JOIN total_count
order by android_version, android_model, _0x0_count desc, device_model_count desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment