2

因此,我将 SQL 与图表工具一起使用,并且我无法将我的指标存储桶反映为 y 轴(作为堆叠列)中的总比例与 x 轴中的指标。

示例:指标(x 轴值)应为“作业计数”、“访问次数”、“应用程序”和“支出”。每个都应该有一个基于以下访问指标桶的堆叠列:

1-2 次访问、3-4 次访问、5-7 次访问、8-10 次访问、11-15 次访问、16-25 次访问和 25 次以上访问。

我的查询如下:

select
  alias.grp as Bucket
  , count(alias.jobid) as Number_Of_Jobs_by_Bucket
  , sum(alias.total_visits) as Visits_by_Bucket
  , sum(alias.spend) as Spend_by_Bucket
  , sum(alias.Total_applications) as Apps_by_Bucket
from
  (
    select
      analytics.jobid
      , case
        when sum(analytics.visits) >= 1
        and sum(analytics.visits) <= 2
          then 'A: 1-2 Visits'
        when sum(analytics.visits) > 2
        and sum(analytics.visits) <= 4
          then 'B: 3-4 Visits'
        when sum(analytics.visits) > 4
        and sum(analytics.visits) <= 7
          then 'C: 5-7 Visits'
        when sum(analytics.visits) > 7
        and sum(analytics.visits) <= 10
          then 'D: 8-10 Visits'
        when sum(analytics.visits) > 10
        and sum(analytics.visits) <= 15
          then 'E: 11-15 Visits'
        when sum(analytics.visits) > 15
        and sum(analytics.visits) <= 25
          then 'F: 16-25 Visits'
        when sum(analytics.visits) > 25
          then 'G: 25+ Visits'
      end as grp
      , sum(analytics.visits) as Total_Visits
      , sum(analytics.total_spend100)/100 as Spend
      , sum(analytics.applications) as Total_Applications
    from
      analytics
    where
      visits > 0
    group by
      analytics.jobid
  )
  as alias
where
  alias.total_visits > 0
group by
  alias.grp
order by
  alias.grp

因此,我尝试使用子查询来定义存储桶,但无法通过存储桶获取每个指标的百分比以落入 Y 轴(因为它是文本值)。理想情况下,我会显示四列(按指标),每列显示例如第一个存储桶的 10%,第二个存储桶的 25%,第三个存储桶的 4%,等等。

关于改进查询以支持这一点的任何想法?

谢谢!

4

0 回答 0