我有两个表sales
和sales_stg
。第一个是源表,第二个是临时表。
While doing the audit to find out the inconsistency between the above two tables, I am getting amount even though no row exists in staging table.
DDL、DML 语句和审计查询在 SQL fiddle 中给出 http://www.sqlfiddle.com/#!2/b3333/2
最佳答案
要查找不一致的记录,您可以使用从您的查询派生的查询
select sum(SL.sales_amt) as SALES_SUM, sum(ST.sales_WIP_amt) as SALES_STG_SUM, SL.sales_id, SL.location
from sales SL INNER JOIN sales_stg ST
ON SL.sales_id = ST.sales_id
group by SL.sales_id, SL.location
having SALES_SUM != SALES_STG_SUM
如果这不是您想要的,您必须更详细地解释您想要做什么。
关于mysql - 在选择查询中获取无效值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25957460/