Sql 使用单个条目连接多行
目标是在一行中获取所有相关信息。事件表在其各自的表中包含联系人和位置。这些关系存储在名为eventrelation的表中,其中有父(事件)和子(联系人、位置)引用 各表如下:Sql 使用单个条目连接多行,sql,database,join,Sql,Database,Join,目标是在一行中获取所有相关信息。事件表在其各自的表中包含联系人和位置。这些关系存储在名为eventrelation的表中,其中有父(事件)和子(联系人、位置)引用 各表如下: 1. event : id ... 2. contact : id ... 3. location : id ... eventrelation : pid | cid | p_type | c_type pid = foreign key (event.id) cid = id of contact or locati
1. event : id ...
2. contact : id ...
3. location : id ...
eventrelation : pid | cid | p_type | c_type
pid = foreign key (event.id)
cid = id of contact or location
p_type && c_type are type of data shown as no above
i.e. 1:event, 2:contact, 3:location
与一个事件相关的所有关联联系人和位置信息都可以返回到与该事件相同的行中。为了得到答案,我尝试了以下查询(有错误)
这些表包含以下数据(例如)
查询结果为:
RESULT
E | C | L
1 1 #
1 # 1
2 1 #
3 # #
在一行中获取联系人和位置时会出现错误,而在当前示例中,它们显示为不同的行。理想的结果应该是:
RESULT
E | C | L
1 1 1
2 1 #
3 # #
创建联接的哪一步是错误的?向下投票,因为该问题写得很糟糕。我编辑了该问题,试图让它更清楚,它仍然不可读吗?
RESULT
E | C | L
1 1 #
1 # 1
2 1 #
3 # #
RESULT
E | C | L
1 1 1
2 1 #
3 # #