sql - 总和列 Oracle
问题描述
您好,我在 3 个表中有数据,代码如下。
甲骨文
select distinct
t2.coll_no,
t1.account_number,
t1.commitment_number,
t3.APPRAISAL_AMT
from table1 t1
LEFT JOIN table2 t2
ON T2.OBLIGATION_ACCOUNT_NUMBER = T1.ACCOUNT_NUMBER
AND T2.OBLIGATION_NUMBER = T1.COMMITMENT_NUMBER
LEFT jOIN table3 t3
ON t3.COLL_NO = t3.cOLL_NO
每个 coll_no 都有不同的 afs_appraisal 数量。
而不是 5 行,唯一的区别是评估金额,我想要一行 5 个评估金额的总和。
解决方案
我想你只想要条件聚合:
select sum(case when t2.coll_no = <val1> then t3.appraisal_amt end) as appraisal_1,
sum(case when t2.coll_no = <val2> then t3.appraisal_amt end) as appraisal_2,
sum(case when t2.coll_no = <val3> then t3.appraisal_amt end) as appraisal_3,
sum(case when t2.coll_no = <val4> then t3.appraisal_amt end) as appraisal_4,
sum(case when t2.coll_no = <val5> then t3.appraisal_amt end) as appraisal_5
from table1 t1 left join
table2 t2
on T2.OBLIGATION_ACCOUNT_NUMBER = T1.ACCOUNT_NUMBER and
T2.OBLIGATION_NUMBER = T1.COMMITMENT_NUMBER left join
table3 t3
on t3.COLL_NO = t3.cOLL_NO;
推荐阅读
- python - 在切片字符串中插入字符串(Python)
- cdo-climate - CDO 气候数据操作员在 Cygwin (Win8) 中停止工作
- powershell - 换行后选择字符串
- reactjs - 如何键入提供道具的高阶组件
- laravel - Laravel 8 - 分页不显示数字
- python - 如何使用 Tesseract 获取图像的文本
- python - 字符串到字节 Python
- flutter - Flutter - 在应用程序内打开特定应用程序的商店/市场屏幕
- php - 如何使用此代码的替代方法?我试图从我的数据库中为访问我的页面的每个用户提供不同的数字
- kerberos - 阿帕奇长凳。带有 Kerberos 身份验证的 API