mysql - 如何加入 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
``
解决方案
你想要的方式,它看起来像一系列UNION
edselect
语句,例如
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>
推荐阅读
- sql-server - 奇怪的 FULL OUTER JOIN “ON” 子句?
- python - 如何将 FFmpeg 命令行转换为 ffmpeg-python 代码?
- amazon-web-services - 用于 aws 策略列表的 terraform 模板文件
- websocket - 直接从socketio服务器获取连接的sid?
- python - Python 猜词游戏
- firebase - firebase 数据库规则的条件
- python - 减少张量的维度(到标量)
- javascript - 在具有不同行数和单元格的其他 div 上复制 javascript 生成的表
- unity3d - Agora 中的语音平移在非常小的“平移”值下是全有或全无,并且大大降低了音量
- linux-kernel - 关于Linux内核分页表的问题