Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Excluir itens de acordo com um registro

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

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