多个SQL连接在两个表上

huangapple go评论66阅读模式
英文:

Multiple SQL Joins on Two Tables

问题

我需要创建一个基于匹配两个表记录的表,让我们称它们为表p和表c,在SQL Server中。在Excel中手动执行此操作是将表p中的订单列与表c中的订单列进行匹配。一旦这些匹配成功,您将取表c中的相应批次列与表p中的批次列进行匹配。一旦这些匹配成功,然后您将取表p中的相应订单列再次与表c进行匹配,这就是我们要提取的最终项。有什么想法?

英文:

I need to create 1 table based on matching the records of two tables, lets call them table p and table c, in SQL Server. The manual way to do this in Excel is to match the Order Column in table p with the Order Column in table c. Once those are matched, you take the corresponding Batch Column in table c and match it with the Batch Column in table p. Once those are matched you then take that corresponding Order Column in table p and match it with table c again and thats the final item we want to pull. Any ideas?

答案1

得分: 1

以下是翻译好的部分:

"It's hard to say for sure given the lack of table definitions, but it sounds as though you need to do two joins, once over to table c, then back again to table p, which you would alias in order to pull the right column value. Perhaps this will help you get started.

SELECT p1.Order
FROM p
INNER JOIN C
ON p.Order = c.Order
INNER JOIN p as p1
ON p1.brance = c.branch"

英文:

It's hard to say for sure given the lack of table definitions, but it sounds as though you need to do two joins, once over to table c, then back again to table p, which you would alias in order to pull the right column value. Perhaps this will help you get started.

SELECT p1.Order
FROM p
INNER JOIN C
ON p.Order = c.Order
INNER JOIN p as p1
ON p1.brance = c.branch

huangapple
  • 本文由 发表于 2023年2月8日 22:41:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75387393.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定