[英]Inner join 2 tables based on 2 columns in one and one column in the other
I have two tables I am wanting to inner join. 我有两个要内部连接的表。 The column of one is Ordind000.PROCPLANID
. 一个的列是Ordind000.PROCPLANID
。 This has the job, the J000012345
, and suffix, the .00001
both in this one column. 这样做的工作,在J000012345
,和后缀,在.00001
都在此一列。 But in the Job
table that I need to join it to, both the job and the suffix are separate columns. 但是在需要将其加入的Job
表中,job和后缀都是单独的列。
My guess is I need to use the replace command and write it to a temp table, but I am hoping for a much easier solution. 我的猜测是我需要使用replace命令并将其写入临时表,但我希望有一个更简单的解决方案。 I will also need to strip the decimal at the beginning of the job
and suffix
numbers in the PROCPLANID
columns I think. 我还需要PROCPLANID
job
开头的小数和我认为的PROCPLANID
列中的suffix
数字。
There are a lot of ways you could manipulate this, here is one: 您可以通过多种方式来操纵它,这是一种:
SELECT columns
FROM table1 t1
INNER JOIN table2 t2 on
SUBSTRING(t1.procplanid,2,10) + RIGHT(t1.procplanid,1) = t2.job + t2.suffix
This will compare the job
portion of procplanid
(without the decimal) +
the last digit of procplanid
as the suffix
, to job + suffix
这会将procplanid
的job
部分(不带小数点) +
procplanid
的最后一位作为suffix
,与job + suffix
Highlighted examples in the image will become: 图像中突出显示的示例将变为:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.