【发布时间】:2021-05-04 00:19:05
【问题描述】:
我有 2 张桌子。我想找到不匹配的行
Input
Table name: sale_order
header_id name date_col total_amt
45 apple 2021-01-26 19:55:33.350589 100
32 grape 2021-01-27 19:55:33.350589 200
22 plums 2021-01-27 17:55:33.350589 250
30 lemon 2021-01-28 19:55:33.350589 400
Table name: bill_order
id product_id date_col total_amt
1 45 2021-01-26 19:55:33.350589 200
2 32 2021-01-27 19:55:33.350589 200
3 22 2021-01-27 17:55:33.350589 500
4 30 2021-01-28 19:55:33.350589 400
输出:不匹配(total_amt 中的值错误)
select sale_order.header_id ,sale_order.total_amt,bill_order.total_amt
FROM sale_order
INNER JOIN bill_order ON sale_order.total_amt != bill_order.total_amt` and
header_id = product_id
预期输出:
header_id total_amt total_amt
45 100 200
22 250 500
我想找出不匹配的 total_amt。 并想展示 我想找到不匹配的 total_amt。 并想显示
我想找出不匹配的 total_amt。 并想显示
【问题讨论】:
-
我非常怀疑一个表中的
header_id会匹配另一个表中名为product_id的东西。您确定您的问题正确反映了数据模型吗?另外,您是否关心其中一张桌子是否缺少某些东西?
标签: sql postgresql join inner-join