[英]Oracle - SQL Query to return a value from a column in another table where value equals a different column
From within the results of a query I need to take the first 3 digits (got this part - substr) from a column in one table and pull the value from a second table where the 3 digit code is in a different column of the same row. 从查询的结果中,我需要从一个表中的列中获取前3位数字(获取此部分-substr),并从第二个表中提取值,其中3位代码位于同一行的不同列中。 While I'm not looking for assistance in this part I will be grouping by the code column for reference
虽然我在本部分中没有寻求帮助,但我将按代码列进行分组以供参考
Example
Table 1 Table 2
3_Digit Code_Column Description
123456 123 Blue
103456 103 Green
so if my substr query return 123 5 times I'm looking for 所以如果我的substr查询返回123 5次,我正在寻找
Blue 3
select t2.Code_Column, count(*)
from table1 t1
join table2 t2
on substr(t1.digit, 0, 3) = t2.Code_Column
group by t2.Code_Column
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.