SQL Select 使用不同行中的值组合 table
SQL Select using combination of values from row in different table
标题中很难解释。新手在此
我有一个包含 2 列的临时 table。
| numdoc | linha |
| 1 | 5 |
| 233423 | 7 |
| 34663 | 4 |
现在我需要使用这些值来制作 select,如下所示:
select *
from wgcdoclinhas
where numdoc in (numdoc from #temptable)
and linagrup (linha from #temptable)
我希望将此设置为 return 行,其中的值与 #temptable 中的值匹配,但不混合值。因为我写的查询没有做出那种区分。每行只有一个结果。
例如,我的#temptable 中有 300 行,我想要的结果是显示 300 行。
我对上述#temptable 查询运行 的期望结果将显示3 行,每一行对应#temptable。
- 1 个结果,其中 numdoc=1 和 linagrup=5,
- 另一个用于 numdoc=233423 和 lnagrup=7
- 最后是 numdoc=34663 和 linagrup=4
我理解如果这还不够清楚,希望它是。
谢谢。
您只需将临时 table 加入您的 table 即可获得您需要的结果:
select w.*
from wgcdoclinhas w
inner join #temptable t
on w.numdoc = t.numdoc AND w.linha = t.linha
如果您使用 JOIN 查询,您的问题将得到解决。
SELECT A.numdoc,A.numdoc
FROM wgcdoclinhas A,#temptable T
WHERE A.numdoc = T.numdoc AND A.linha = T.linha
标题中很难解释。新手在此
我有一个包含 2 列的临时 table。
| numdoc | linha |
| 1 | 5 |
| 233423 | 7 |
| 34663 | 4 |
现在我需要使用这些值来制作 select,如下所示:
select *
from wgcdoclinhas
where numdoc in (numdoc from #temptable)
and linagrup (linha from #temptable)
我希望将此设置为 return 行,其中的值与 #temptable 中的值匹配,但不混合值。因为我写的查询没有做出那种区分。每行只有一个结果。
例如,我的#temptable 中有 300 行,我想要的结果是显示 300 行。
我对上述#temptable 查询运行 的期望结果将显示3 行,每一行对应#temptable。
- 1 个结果,其中 numdoc=1 和 linagrup=5,
- 另一个用于 numdoc=233423 和 lnagrup=7
- 最后是 numdoc=34663 和 linagrup=4
我理解如果这还不够清楚,希望它是。
谢谢。
您只需将临时 table 加入您的 table 即可获得您需要的结果:
select w.*
from wgcdoclinhas w
inner join #temptable t
on w.numdoc = t.numdoc AND w.linha = t.linha
如果您使用 JOIN 查询,您的问题将得到解决。
SELECT A.numdoc,A.numdoc
FROM wgcdoclinhas A,#temptable T
WHERE A.numdoc = T.numdoc AND A.linha = T.linha