mysql - 在选择查询中获取无效值

标签 mysql sql join

我有两个表salessales_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/

相关文章:

mysql - 通过批处理脚本创建mysql odbc连接

sql - 在 Derby DB 中,是否可以使用单个查询添加多个列?

MySQL为特定c中的每种类型选择一定数量的行

sql - 如果第二个表中不存在条目,则加入

python - django.db.utils.OperationalError : (2013, "Lost connection to MySQL server at ' 握手 : reading inital communication packet', 系统错误:0")

mysql - 提高查询速度 : simple SELECT from SELECT in huge table

php - 如何将sql查询结果放入数组?

java - 尽管查询正在从数据库控制台运行,但 Hibernate 抛出异常

php - 获取与多个属性过滤器匹配的产品(实体属性值)

python pandas dataframe 连接两个数据框