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

Ekskluder elementer i henhold til en registrering

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

output:

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


  1. Hvordan taler Access med ODBC-datakilder? Del 4

  2. Sådan fungerer ADD_MONTHS() i MariaDB

  3. psql.exe - adgangskodegodkendelse mislykkedes i Windows

  4. jBPM 6.5 + Tomcat 8 + Bitronix-transaktion + Oracle 11G-konfiguration | Kunne ikke begå session java.lang.NullPointerException