postgresql - 此查询如何填充数据?
问题描述
据我了解,当此查询运行时,由于 where 子句,它不会在运行任何次数时填充任何数据
where c.company_id = lot.company_id
and p.product_id = lot.product_id
and l.packlevel_id = lot.packlevel_id
在我看来,一开始当表fact_table_lot
为空时,where 子句将返回空数据,因为它不会在空表中找到任何内容,并且每次都会发生。我的理解错了吗?
insert into fact_table_lot(company_id, product_id, packlevel_id, l_num, sn_count, comm_loct, comm_start, commdate_end, man_date, exp_date, user_id, created_datetime)
select c.company_id, p.product_id, l.packlevel_id, l_num, sn_count, comm_loct, comm_start, commdate_end, man_date, exp_date, user_id, sysdate
from staging_serials s
left outer join fact_table_lot lot on s.lotnumber = lot.l_num
join company c on c.lsc_company_id = s.companyid
join product p on s.compositeprodcode = p.compositeprodcode
join level l on l.unit_of_measure = p.packaginguom
where c.company_id = lot.company_id
and p.product_id = lot.product_id
and l.packlevel_id = lot.packlevel_id
and lot.created_datetime is null
解决方案
在您的查询staging_serials s left outer join fact_table_lot lot on s.lotnumber= lot.l_num
中,这将提供包含来自事实表的所有记录的结果集staging_serials
,因为事实表对于事实表中的那些列是空的空值。如果您不希望返回任何记录,请使用 ainner join
而不是left join
.
推荐阅读
- javascript - 严重:错误:未知方法返回类型:QList
- sqlite - Entity Framework Core with SQLite:如何在不过度膨胀临时文件的情况下包含来自多个相关表的记录?
- python - 如何在使用 python 脚本或 pandas 读取 xlsb 文件时忽略隐藏行
- flutter - 为什么我的 Flutter 动画复选标记不起作用?
- localhost - 电子邮件发送代码在 localhost 但不在 IONOS 服务器上工作
- vue.js - 您可能需要适当的加载程序来处理此文件类型。它不允许在 node_modules 中使用 html
- flutter - 在 null 上调用了方法“数据”
- php - Yii2 表单字段使用正则表达式修改值
- html - 在角度中,我的内容是从 api 获取的,内容具有内联样式 css。我正在使用innerHTML="variable"。样式不起作用
- c# - 匹配连续的 2 位或 3 位