在项目开发中遇到这么一个例子,首先产品表
tb_product
-----------------------------
id name
1 手机
2 电脑
3 笔记本
第二张表
tb_product_chain(产品链)
------------------------------------------------------
int product_id parent_product_id
1 1 2
2 1 3
需要新建一个查询,即把表2中的product_id和parent_product_id替换为产品的name
我们可以这么操作
select a.id,b.name,c.name
from tb_product_chain a
inner join tb_product b on a.product_id=b.id
inner join tb_product c on a.parent_product_join=c.id
发现结果是
1 手机 电脑
2 手机 笔记本
达到了预期效果。
一下是我的项目中的实际操作数据
tb_product_chain
tb_product
v_product_chain
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有