请看下面,当然我是用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
可用count函数来计算某个字段重复次数。
如test表中数据如下:
现在要查询name列中,各个名字重复的次数,可用如下语句:
select name,count(*) from test group by name;查询结果: