【问题标题】:Oracle SQL Count grouped rows in tableOracle SQL 计数表中的分组行
【发布时间】:2018-03-19 19:13:21
【问题描述】:

我想知道是否可以最好在 PL/SQL V11 上使用 select 语句从该表中获得以下结果:

Area    Store   Product
10      1       A
10      1       B
11      1       E
11      1       D
10      2       C
10      2       B
10      2       A
10      3       B
10      3       A
13      1       B
13      1       A

并返回此结果,因此它按区域分组,并存储并查找具有相同产品的区域和存储。因此,Area 10 Store 1 有产品 A 和 B,因此它会查看列表中只有 A 和 B 的其他商店并计算它们。在此示例中,它计算区域 10 商店 1/区域 10 商店 3/区域 13 商店 1。

Product Count of groups
AB      3
ABC     1
DE      1

提前感谢您的帮助。

【问题讨论】:

    标签: sql oracle group-by count


    【解决方案1】:

    是的,您可以使用listagg(),然后使用另一个group by

    select products, count(*)
    from (select listagg(product) within group (order by product) as products
          from t
          group by area, store
         ) p
    group by products;
    

    【讨论】:

      猜你喜欢
      • 2021-04-11
      • 2012-12-31
      • 2016-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-23
      • 1970-01-01
      相关资源
      最近更新 更多