首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过交互器连接不同的ids

通过交互器连接不同的ids
EN

Stack Overflow用户
提问于 2019-09-03 07:25:29
回答 2查看 32关注 0票数 0

我想通过普通的交互程序链接不同的ids。这是有点复杂,但我会尽我最大的努力来描述这个问题。

以下是步骤1的列表。从表A提取id。

代码语言:javascript
复制
Table A 

    ID   Interactor
    1   30
    2   40
  1. 从表B中获取与id对应的中间参与者列表。例如, select * from table B where id = 1

表B

代码语言:javascript
复制
ID   Interactors
1   30
1   32
1   33
1   36
1   38
1   39
  1. 从列表中迭代每个interactor,并从表A中获得ids列表。
代码语言:javascript
复制
Table  A    

    ID  Interactors 
    1   30
    70  32
    76  33
    Null    36
    89  38
    75  39
    2   45
    2   40
    2   43

4.加入这些不同的ids,以便当我选择1时,我应该得到以下结果。

Select * where id = 1

结果

代码语言:javascript
复制
    ID  Interactors 
    1   30
    70  32
    76  33
    89  38
    75  39

我希望使用sql来实现这一点。

EN

回答 2

Stack Overflow用户

发布于 2019-09-03 07:47:50

试试这个:

代码语言:javascript
复制
select B.ID, B.Interactors 
from A inner join B 
where A.Interactors = B.Interactors 
and A.ID = 1
票数 0
EN

Stack Overflow用户

发布于 2019-09-03 08:14:29

从步骤3开始,您有table A,在此之前,您有table B

您可以使用简单的inner join和where条件来获得您想要的结果。

代码语言:javascript
复制
Select Id, Interactors from
   ( select tableA.id, tableA.Interactors 
     from tableA 
          inner join tableB 
          on tableA.Interactors = tableB.Interactors 
             and tableA.Id is not null    --- this is required since in your output record having NULL id correspond to tableA is not considered
    ) as db
where db.Id = 1    ---- you can apply any filter over there to get your desired result.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57766863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档