sql - 如何在sql中获取列值作为表列
问题描述
这是我在数据库中定义的表:
pi_value | Status
------------+-------------------
500.000 | Bank Submitted
500.0000 | Bank Submitted
1000.0000 | Maturity Received
4000.0000 | Bank Submitted
50.0000 | Maturity Received
我希望输出看起来像这样:
Maturity Received | Bank Submitted |
------------------+----------------+
1050.0000 | 5000.0000 |
------------------+----------------+
解决方案
使用条件聚合
select sum(case when status='Bank Submitted' then pi_value else 0 end),
sum(case when status='Maturity Received' then pi_value else 0 end) from table
推荐阅读
- flutter - 类'列表
' 在颤振应用程序中没有实例 getter 'docs' - java - 微服务的 GET 请求上的 Servlet.service I/O 错误
- swift - 调用中缺少参数“studyCard”的参数
- javascript - 我可以在 backdraftjs 的复合组件中指定子级的位置吗?
- visual-studio-code - 有没有办法在 Visual Studio Code 中当前打开的选项卡之间进行搜索和选择?
- javascript - 如何创建具有共同道具值的对象数组
- spring-boot - 在 Spring Boot 项目中限制除 GET 之外的其余 API 方法
- angular - 从服务工作者 javascript 文件调用 Angular Service 方法
- c# - 如何围绕不同的解决方案共享 Azure 功能?
- python - 有没有更快的方法来查找列表列表中两个元素的共现