如何比较两个不同表的日期和值

问题描述 投票:0回答:1

我有两个包含相同列名的表,PMS 每天都会变化,所以两个表 date、emp.代码,需要和PMS进行比较。如果两个表在同一日期的员工的 PMS 值不同,我需要提到的输出。

表1

身份证 日期 emp。代码 经前综合症
1 2023-12-01 V1856 5
2 2023-12-10 V2584 4
3 2023-12-15 V3643 5
4 2023-12-15 V1856 5
5 2023-12-16 V2584 6

表2

身份证 日期 emp。代码 经前综合症
1 2023-12-01 V1856 4
2 2023-12-10 V2584 4
3 2023-12-15 V3643 5
4 2023-12-15 V1856 5
5 2023-12-16 V2584 2

需要输出

身份证 日期 emp。代码 tbl1_经前综合症 tbl2_经前综合症
1 2023-12-01 V1856 5 4
2 2023-12-16 V2584 6 2

请建议MySQL代码。

mysql illegalargumentexception
1个回答
0
投票

您可以使用

INNER JOIN
连接两个表,然后选择不匹配的数据来实现此目的:

select t1.ID, t1.Date, t1.emp_code, t1.PMS as tbl1_PMS, t2.PMS as tbl2_PMS 
from table1 t1
inner join table2 t2 on t1.ID = t2.ID 
                    and t1.Date = t2.Date
                    and t1.emp_code = t2.emp_code
where t1.PMS <> t2.PMS
© www.soinside.com 2019 - 2024. All rights reserved.