查找2列组合的计数-Oracle SQL

时间:2019-03-20 14:46:23

标签: sql oracle

我有一张桌子

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

我怎么找到它?

2 个答案:

答案 0 :(得分:3)

按col1和col2分组:

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

答案 1 :(得分:2)

简单的聚合将起作用:

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