oracle里怎么统计某个字段出现的重复次数

如题所述

第1个回答  2019-08-20
请看下面,当然我是用SQL SERVER来写。但是在ORACLE能通用。
select
B.ID,

case
when
B.h
IS
null
then
0
else
B.h
end
as
h,

case
when
B.t
IS
null
then
0
else
B.t
end
as
t,

case
when
B.g
IS
null
then
0
else
B.g
end
as
g
from
(

SELECT
distinct
ID,

(select
[COUNT]
from

where
ID=a.id
and
RA=100)
as
h,

(select
[COUNT]
from

where
ID=a.id
and
RA=200)
as
t,

(select
[COUNT]
from

where
ID=a.id
and
RA=300)
as
g

from

A

)
B
第2个回答  2019-11-20
可用count函数来计算某个字段重复次数。
如test表中数据如下:

现在要查询name列中,各个名字重复的次数,可用如下语句:
select name,count(*) from test group by name;查询结果:
相似回答