第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