微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

多个表连接重复行是主键的问题吗?

如何解决多个表连接重复行是主键的问题吗?

我想将这三个表连接在一起,但结果不符合我的预期。

表 1:Brand_Table_ID:(customer_ID & Product_ID & Sub_type_product_ID)

Brand_Table_ID customer_ID Product_ID Sub_type_product_ID Brand_Value
AAA01_PPP01_01 AAA01 PPP01 01 A 2021/06
AAA01_PPP01_02 AAA01 PPP01 02 A 2021/06

表 2:Potential_Table_ID:(customer_ID & Product_ID & Sub_type_product_ID)

Potential_Table_ID customer_ID Product_ID Sub_type_product_ID Potential_Value
AAA01_PPP01_01 AAA01 PPP01 01 2021/06
AAA01_PPP01_02 AAA01 PPP01 02 2021/06

表 3 Transaction_ID : (customer_ID & Product_ID & Sub_type_product_ID)

Transaction_ID customer_ID Product_ID Sub_type_product_ID Salesperson_ID
AAA01_PPP01_01 AAA01 PPP01 01 SSS01 2021/06
AAA01_PPP01_02 AAA01 PPP01 02 SSS02 2021/06

结合这三个表后,我预计结果是:

Transaction_ID customer_ID Product_ID Sub_type_product_ID Salesperson_ID Brand_Value Potential_Value
AAA01_PPP01_01 AAA01 PPP01 01 SSS01 A 2021/06
AAA01_PPP01_02 AAA01 PPP01 02 SSS02 A 2021/06

然而,我得到了这个结果

Transaction_ID customer_ID Product_ID Sub_type_product_ID Salesperson_ID Brand_Value Potential_Value
AAA01_PPP01_01 AAA01 PPP01 01 SSS01 A 2021/06
AAA01_PPP01_02 AAA01 PPP01 02 SSS02 A 2021/06
AAA01_PPP01_02 AAA01 PPP01 02 SSS01 A 2021/06
AAA01_PPP01_02 AAA01 PPP01 02 SSS02 A 2021/06

我想知道发生了什么情况。是不是因为主ID在这三个表之间不是唯一的?

如果是,将唯一 ID 设计为 (customer_ID & Product_ID & Sub_type_product_ID & Salesperson_ID) 或 (customer_ID & Product_ID & Sub_type_product_ID & Salesperson_ID & Month)很棒吗?

或者,在我合并表格之前,它是否有我应该知道的额外知识?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。