【问题标题】:Find count of combination of 2 columns - Oracle SQL [duplicate]查找2列组合的计数-Oracle SQL [重复]
【发布时间】:2019-03-20 14:46:22
【问题描述】:

我有一张桌子

table_user
col1      col2
123       456
124       457
125       458
126       459
127       460
128       461
123       456
123       456
123       457

我需要找出 col1 和 col2 与计数的组合。

在上面的例子中:

col1      col2   count_combination
123       456    3
123       457    1
124       457    1
125       458    1
126       459    1
127       460    1
128       461    1

我怎样才能找到它?

【问题讨论】:

    标签: sql oracle


    【解决方案1】:

    按 col1、col2 分组:

    select col1, col2, count(*) count_combination
    from table_user
    group by col1, col2
    

    【讨论】:

      【解决方案2】:

      简单的聚合就可以了:

      select co1l, col2, count(*) as count_combination
      from table_user
      group by co1l, col2;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-06-29
        • 2019-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-22
        • 1970-01-01
        相关资源
        最近更新 更多