【发布时间】:2021-12-16 16:56:24
【问题描述】:
我有 4 张桌子。
1st table has: date and revenue
2nd table has: date and cost
3rd table has: date and fees
4th table has: date and others
我正在使用以下公式计算最终收入值:
final = revenue - (cost + fees + others)
为了执行此操作,我在对所有这 4 个表执行左外连接时使用了合并操作。由于左外层的连接顺序很重要,所以当没有收入或成本时,我会错过费用。
Join order is revenue => cost => fees => others tables on date.
如果收入/成本缺失但费用/其他存在,我如何在缺失日期显示这些缺失行?
【问题讨论】:
-
请添加查询
-
这4个表格中的任何一个都可能缺少某个确定的日期,是吗?
标签: mysql join left-join coalesce