比较多个Mysql表以查找修改记录
我有三个表作为 SQLITE3 转储。
产品、税收、库存
从这些表中准备一个 csv 文件以导入到 magento 产品部分。那么这部分就结束了。
现在必须运行每日脚本来更新库存、税费、修改的产品详细信息(SKU 在任何情况下都不会更改)。
在本次更新部分。 例如,我有 12000 条记录,因为最后一天的数据库中的库存表、税务表、产品表中可能只有 400 或 1000 条记录发生变化/修改/更新。其余行将保持不变。
因此,我将最后几天的表格添加为 old_products,old_tax,old_inventory。
并尝试编写 sql 查询以从两组表中仅提取修改的记录
(注意:两组表都在同一数据库中可用。)
请任何人帮助我如何编写 sql 查询来提取通过比较两组表来修改记录。
I have three tables as a SQLITE3 Dump.
products,tax,inventory
From these tables preparing a csv file to import into magento products section. SO that part is over.
Now have to run a daily script which updates the inventory,tax, modified product details(SKU will not change at any case).
In this update section.
For example, i have 12000 records, in that only may be 400 or 1000 records varied/modified/updated in inventory table,tax table,products table from the last day's Database. The remaining rows will remain same.
So i added the last days tables as old_products,old_tax,old_inventory.
And tried to write sql query to extract only modified records from the two set's of tables
(Note: Both sets of tables available in Same Db.)
Please can anyone help me how to write a sql query to extract the modified records by comparing two sets of tables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能会改变这个模式。
我将有一个表,用于存储上次将数据导出到 CSV 时的日期:
然后我可以在三个表中的每一个中都有一个时间戳列,用于保存上次修改时间戳。我会有一个更新该专栏的触发器。
然后,查询修改后的数据以进行另一次导出就像将
LastModified
列与CSVLastExported
中的相应列进行比较一样简单:I would probably change this schema.
I would have a table where I would store the date(s) when I last exported the data to CSV(s):
And I could then have a timestamp column in each of the three tables which would hold the last modification timestamp. I would have a trigger for updating that column.
Querying the modified data for another export would then be as easy as comparing the
LastModified
column against the corresponding column inCSVLastExported
:这为您提供了所有修改(和产品):
这是修改后的产品:
this gives you all modifications (and the product):
and this the modificated products: