【问题标题】:Presto SQL Map to ColumnsPresto SQL 映射到列
【发布时间】:2020-06-29 18:03:25
【问题描述】:

我正在尝试从地图创建一些列,有人可以帮忙吗? 我的查询是这样的:

     select
           multimap_agg(produtos,amount) products  ,"seller" seller from
     self_service_data.self_inside_field_sales
     where pipeline = '[IS] Closer Pipeline'
     group by 2

我有这样的结果:

我正在尝试与小团体一起获得一张桌子:

Seller, Number of Products (A+B) sold,   sum(amount), Number of Products sold(C+D),  sum(amount)

【问题讨论】:

  • 请以表格文本形式向我们展示原始表格中的示例数据(不是您的查询结果)和预期结果。

标签: sql group-by sum presto


【解决方案1】:

我看不出使用地图的意义。从您预期结果的结构来看,简单的聚合似乎可以完成工作:

select
    seller,
    produtos,
    count(*) no_produtos,
    sum(amount) sum_amount
from self_service_data.self_inside_field_sales
where pipeline = '[IS] Closer Pipeline'
group by seller, produtos

【讨论】:

  • 我使用地图是因为我有一些我想查看的小组,例如:卖家、Count(Product A+B)、Sum(Amount1)、Count(Product C+D)、... ...我可以使用您的查询 + 连接来制作这个产品,但它非常昂贵(+7 连接)。使用地图我希望减少这种情况。我会重新提出这个问题,对不起,如果不是误导
猜你喜欢
  • 1970-01-01
  • 2021-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多