sql - 有没有办法在 Postgresql 中获得以下结果
问题描述
所以有2张桌子。
表格1
month | orders
Jan | 10
Feb | 4
Apr | 7
表2
month | dispatch
Jan | 2
May | 3
我想得到以下结果:-
month | orders | dispatch
Jan | 10 | 2
Feb | 4 | 0
Apr | 7 | 0
May | 0 | 3
有什么方法可以解决这个问题?
解决方案
使用完全外连接
select coalesce(t1.month,t2.month),coalesce(t1.orders,0)
,coalesce(t2.dispatch,0)
from table1 t1 full outer join table2 t2 on t1.month=t2.month
推荐阅读
- installation - 如何重新定位 Inno Setup 的卸载程序?
- neovim - Nvim lsp - 更改 lspconfig 诊断消息位置
- amazon-web-services - EKS 中的持久存储无法配置卷
- python - 从 Python 中的 Pandas DataFrame 中随机删除 n 个连续的、不重叠的行
- r - R:while 和 if-else 循环
- docker - 如何创建两个共享代码和资产的 NestJS 存储库?
- android - 尝试通过选择器共享图像时未出现主题和文本
- .net - .NET 5 中的 .NET 插件基础结构和 PowerShell:无法调用 Get-Disk cmdlet
- android-button - 单击报告错误按钮时如何收到报告错误消息
- sql - VS Code 启动配置中的反引号无法转义 SQL 查询中具有特殊字符的列