sql - MS-Access - 根据条件合并两个表之间的数据
问题描述
我正在使用 MS Access,我正在尝试在两个表之间创建一个查询并基于以下条件合并相同的行:
cust_id = cust_id
并且
a_date = f_date
和
price = paid
并有欲望输出。
我现在的数据:
tblapp
app_id cust_id a_date price a_memo
------------------------------------------
1 1 10/10/20 20 hello
2 1 11/10/20 10 bye
3 2 12/10/20 30 hi
4 2 12/10/20 30 text
5 2 12/10/20 30 lol
6 2 12/10/20 30 ciao
7 3 14/10/20 25 peace
tblfin
fin_id cust_id f_date paid
----------------------------------
1 1 10/10/20 20
2 1 11/10/20 10
3 1 11/10/20 10
4 2 12/10/20 30
5 3 14/10/20 25
如你看到的,
cust_id = 1
on 10/10/20
with bill 20
and paid20
cust_id = 1
on 11/10/20
with bill 10
and paid10 + 10
cust_id = 2
on 12/10/20
with bill 30 + 30 + 30 + 30
and paid30
cust_id = 3
on 14/10/20
with bill 25
and paid25
Derire 查询输出:
app_id cust_id a_date price a_memo fin_id cust_id f_date paid
----------------------------------------------------------------------
1 1 10/10/20 20 hello 1 1 10/10/20 20
2 1 11/10/20 10 bye 2 1 11/10/20 10
3 2 12/10/20 30 hi 4 2 12/10/20 30
7 3 14/10/20 25 peace 5 3 14/10/20 25
尝试了以下 sql,但我得到了重复项(例如 cust_id 1 和 2,其中两个表中的数据行不同):
SELECT f.fin_id,
f.cust_id,
f.f_date,
f.paid,
a.app_id,
a.cust_id,
a.a_date,
a.price,
a.a_memo
FROM tblfin AS f
LEFT JOIN tblapp AS a ON (f.cust_id=a.cust_id)
AND (f.f_date=a.a_date)
AND (f.paid=a.price);
欢迎使用 MySQL 的解决方案。谢谢你。
解决方案
推荐阅读
- mysql - 在asp和mysql中登录并创建会话后,如何更改导航栏?
- javascript - 如何在 Node.JS 中使用多个 SQL Server 查询
- javascript - Express how to pass .json into res.render
- javascript - 在这两种方法中,保持响应直到数据获取循环在 nodejs 中结束的最佳方法是什么?
- python - 在使用类线性回归时获得 nan
- python - Python Altair 如何在不更改轴刻度的情况下对直方图数据进行分箱
- python - 我能做些什么来修复我在 python 中工作的这个 GPA 计算器
- c# - 在某些 API 端点上转发 Mailgun 操作
- arrays - 将大型文件文件夹加载到 Julia 以比较每个文件的列的最佳方法是什么?
- electron - 分离多个窗口的cookies