现有表A共三个字段:id,beforePacketId(前置附件包id),afterPacketId(后置附件包id),现有一条数据,假设beforePacketId的附件包里面有2个附件,afterPacketId的附件包里面有3个附件,请问如何查询可以得到如下图所示的3条数据
SELECT
a.[ID],
b.[data] AS 前置附件,
c.[data] AS 后置附件
FROM
A AS a
LEFT JOIN beforePacketId AS b ON a.[beforePacketId] = b.[ID]
LEFT JOIN afterPacketId AS c ON a.[afterPacketId] = c.[ID]
这个数据不是在一个数据库表里的吗?
where条件 后面写 前置附件 in(‘值1’,‘值2’)
SELECT DISTINCT
a.id,
b.后置附件,
c.前置附件
tab_dim a
LEFT JOIN beforePacket b ON a.beforePacketId = b.id
LEFT JOIN afterPacket c ON a.afterPacketId = c.id
WHERE
a.id = 470
————————————————————————