Oracle
 sql >> Database >  >> RDS >> Oracle

Escludi elementi in base a un record

create table #resource
(
    DPTID varchar(10)
    ,FISCAL_YEAR varchar(10)
    ,OPERATING_UNIT varchar(10)
    ,AMOUNT int
)

insert into #resource
select 'PTT','2017','WP', 1200 union all
select 'PTT','2017','SP', 3000 union all
select 'PTT','2017','GP', 1000 union all
select 'FPP','2017','WP', 1000 union all
select 'FPP','2018','GP', 2000 union all
select 'FPP','2017','SP', 1000 union all
select 'FPP','2018','SP', 2000

select * from #resource

select FISCAL_YEAR,DPTID, SUM(AMOUNT) as Amount
from #resource
where OPERATING_UNIT <> 'WP'
group by FISCAL_YEAR,DPTID
order by FISCAL_YEAR,Amount desc


drop table #resource

uscita:

FISCAL_YEAR DPTID   Amount
2017        PTT     4000
2017        FPP     1000
2018        FPP     4000