英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论