【发布时间】:2021-04-25 16:07:39
【问题描述】:
我想将 product_table 中唯一的行插入 bill_table_unique。
然后必须将重复的行从 product_table 移动到 bill_table_duplicate。
一旦所有的数据都被移动了意味着 product_table 条目必须被清除(只有移动的行需要被清除)
输入:
product_table
id bill_id entry_date product_name stock
-------------------------------------------------------------------
1 009 2020-12-11 02:05:20.09876 apple 5
2 009 2020-12-11 02:05:20.09876 apple 5
3 009 2020-09-11 02:05:20.09876 apple 5
4 002 2020-12-11 02:05:20.09876 berry 5
5 002 2020-12-11 02:05:20.09876 berry 5
6 004 2020-12-11 10:05:20.09876 pineapple 1
7 006 2020-12-11 10:05:20.09876 pineapple 4
步骤 1:将 product_table 中唯一的行插入 bill_table_unique。
输出:bill_table_unique
id bill_id entry_date product_name stock
-------------------------------------------------------------------
1 009 2020-12-11 02:05:20.09876 apple 5
2 009 2020-09-11 02:05:20.09876 apple 5
3 002 2020-12-11 02:05:20.09876 berry 5
4 004 2020-12-11 10:05:20.09876 pineapple 1
5 006 2020-12-11 10:05:20.09876 pineapple 4
第 2 步:然后必须将重复的行从 product_table 移动到 bill_table_duplicate。
输出:bill_table_duplicate
id bill_id entry_date product_name stock
---------------------------------------------------------------------
1 009 2020-12-11 02:05:20.09876 apple 5
2 002 2020-12-11 02:05:20.09876 berry 5
第 3 步:一旦所有数据都被移动,意味着 product_table 条目必须被清除(只需要清除移动的行)
输出:product_table
id bill_id entry_date product_name stock
--------------------------------------------------------------------
【问题讨论】:
标签: sql postgresql duplicates unique distinct