在此处寻求一些帮助,以将数据列从另一个表添加到我的查询结果中。
所以两个表上的键都是customer_number
。
我有一个如下查询:
SELECT [CUSTOMER_NUMBER]
,[CUSTOMER_NAME]
,count(*) 'YEARS'
FROM [DB].[dbo].[tablefromxlsimport$]
group by [CUSTOMER_NUMBER]
,[CUSTOMER_NAME]
这返回我正在从tableformxlsimport$
中寻找的信息,但是我想根据查询的结果从另一个表fullcustomerlist$
添加一列数据,该查询的结果将追加一列数据即customer_Current_title
。
希望我能正确解释
答案 0 :(得分:0)
请参见以下查询:
SELECT
A.[CUSTOMER_NUMBER]
,A.[CUSTOMER_NAME]
,A.YEARS
B.customer_Current_title
FROM
( SELECT
A.[CUSTOMER_NUMBER]
,A.[CUSTOMER_NAME]
,count(*) 'YEARS'
FROM [DB].[dbo].[tablefromxlsimport$] AS A
group by [CUSTOMER_NUMBER]
,[CUSTOMER_NAME]
) AS A
INNER JOIN dbo.fullcustomerlist$ AS B on A.CUSTOMER_NUMBER = B.CUSTOMER_NUMBER