mysql - SQL: Stacking columns by bucketed metrics -
so i'm using sql charting tool, , can't buckets of metrics reflect proportions of total in y-axis (as stacked columns) metrics in x-axis.
example: metrics (x-axis values) should "job count", "visits", "apps", , "spend". each 1 should have stacked column based on following bucket of visits metrics:
1-2 visits, 3-4 visits, 5-7 visits, 8-10 visits, 11-15 visits, 16-25 visits, , 25+ visits.
my query follows:
select alias.grp bucket , count(alias.jobid) number_of_jobs_by_bucket , sum(alias.total_visits) visits_by_bucket , sum(alias.spend) spend_by_bucket , sum(alias.total_applications) apps_by_bucket ( select analytics.jobid , case when sum(analytics.visits) >= 1 , sum(analytics.visits) <= 2 'a: 1-2 visits' when sum(analytics.visits) > 2 , sum(analytics.visits) <= 4 'b: 3-4 visits' when sum(analytics.visits) > 4 , sum(analytics.visits) <= 7 'c: 5-7 visits' when sum(analytics.visits) > 7 , sum(analytics.visits) <= 10 'd: 8-10 visits' when sum(analytics.visits) > 10 , sum(analytics.visits) <= 15 'e: 11-15 visits' when sum(analytics.visits) > 15 , sum(analytics.visits) <= 25 'f: 16-25 visits' when sum(analytics.visits) > 25 'g: 25+ visits' end grp , sum(analytics.visits) total_visits , sum(analytics.total_spend100)/100 spend , sum(analytics.applications) total_applications analytics visits > 0 group analytics.jobid ) alias alias.total_visits > 0 group alias.grp order alias.grp
so i'm trying use subquery define buckets cannot percentages of each metric bucket fall y-axis (due being text value). ideally, i'd show 4 columns (by metrics) each 1 showing example 10% first bucket, 25% second bucket, 4% third bucket, etc.
any thoughts on refining query support this?
thanks!
Comments
Post a Comment