【发布时间】:2018-11-27 21:54:30
【问题描述】:
所以我有:
- table1=车辆
- table2=汽车
- table3=摩托车
- table4=卡车...
在表 1 中,我有一个列 type 引用了上述表中的第一个表(表 2 | 表 3 | 表 4 ...)。我想列出表1中的所有车辆并加入type中引用的表;但我发现这有点困难,我发现的唯一方法是获取所有车辆并循环遍历所有车辆,并从type 中指定的相应表中获取补充数据。
例如:
车辆:
id(0)------------type(1)---------------name(dacia)
id(1)------------type(2)---------------name(porsche)
id(2)------------type(2)---------------name(hummer)
id(3)------------type(3)---------------name(kongo)
id(4)------------type(3)---------------name(renault)
汽车(类型 1):
id(0)----------vehicleId(0)-------otherInfo(new)
卡车(类型 2):
id(0)----------vehicleId(1)-------otherInfo(used)
id(1)----------vehicleId(2)-------otherInfo(like_new)
摩托车(3 型):
id(0)----------vehicleId(3)-------otherInfo(old)
id(1)----------vehicleId(4)-------otherInfo(very_old)
查询结果:
id(0)------------type(1)---------------name(dacia)-------otherInfo(new)
id(1)------------type(2)---------------name(porsche)-------otherInfo(used)
id(2)------------type(2)---------------name(hummer)-------otherInfo(like_new)
id(3)------------type(3)---------------name(kongo)-------otherInfo(old)
id(4)------------type(3)---------------name(renault)-------otherInfo(very_old)
【问题讨论】:
标签: mysql sql node.js sequelize.js