首页 > 解决方案 > 如何加入 Apex oracle

问题描述

哈哈哈

请帮我完成我的任务

我有 2 张桌子:

-Nasabah(身份证、姓名、地址)。

-Transaksi_Nasabah (id,nominal,date,kategori,id_nasabah)

在类别中有 2 个值(存款和取款)

ID  NOMINAL DATE        KATEGORI    ID_NASABAH
3   100000  03/02/2020  Deposit       3
5   100000  03/02/2020  Deposit       5
4   100000  03/02/2020  Deposit       4
7   10000   03/09/2020  Deposit       1
13  50000   03/11/2020  Withdtawal    2
14  25000   03/16/2020  Deposit       3
......................................... etc

我必须做

 total deposit       760000
 total withdrawal    130000
 Saldo (Deposit-WD)  630000
 MAX Deposit         100000
 Min Deposit         5000
 Max Withdrawal      50000
 Min Withdrawal      10000
``

标签: mysqlsqloraclesumoracle-apex

解决方案


你想要的方式,它看起来像一系列UNIONedselect语句,例如

SQL> with test (nominal, kategori) as
  2    (select 100, 'Deposit'    from dual union all
  3     select 200, 'Deposit'    from dual union all
  4     select  50, 'Withdrawal' from dual union all
  5     select  30, 'Withdrawal' from dual
  6    )
  7  select 'total deposit' what  , sum(nominal) result from test where kategori = 'Deposit'
  8  union all
  9  select 'total withdrawal'    , sum(nominal) from test where kategori = 'Withdrawal'
 10  union all
 11  select 'saldo (deposit - wd)', sum(case when kategori = 'Deposit' then nominal
 12                                          when kategori = 'Withdrawal' then -nominal
 13                                     end
 14                                    )
 15    from test
 16  union all
 17  select 'max deposit'         , max(nominal) from test where kategori = 'Deposit';

WHAT                     RESULT
-------------------- ----------
total deposit               300
total withdrawal             80
saldo (deposit - wd)        220
max deposit                 200

SQL>

推荐阅读