有没有人知道这个查询有什么问题?我正在尝试对同一服务器上的不同数据库进行内部连接。
SELECT b.company, i.CONCOM,
COALESCE (SUM(CASE WHEN C.CATEGORY_ID = '30' THEN 0 ELSE t .LOGMINS END), 0) AS TotalWithoutNew,
COALESCE (SUM(t.LOGMINS), 0) AS TotalAllId
FROM helpdesk3.dbo.INQUIRY AS i
INNER JOIN [Check].[dbo].[tbl_companies] As B ON
i.CONCOM, B.company
INNER JOIN TIMELOG AS t ON
t.INQUIRY_ID = i.INQUIRY_ID
INNER JOIN PROD AS P ON
i.PROD_ID = P.PROD_ID
INNER JOIN CATEGORY AS C ON
P.CATEGORY_ID = C.CATEGORY_ID
WHERE (DATEPART(yyyy, ESCDATE) =2011)
GROUP BY i.CONCOM
ORDER BY totalwithoutnew desc
答案 0 :(得分:4)
您的第一次加入
INNER JOIN [Check].[dbo].[tbl_companies] As B ON
i.CONCOM, B.company
有列列表而不是连接谓词。你可能意味着i.CONCOM = B.company
。
另一个问题可能在于您的表tbl_companies的完全限定名称。正如本article所述:
要引用列,有三种选择:完全限定,部分限定和不限定。完全指定了完全限定名称(写为db_name.tbl_name.col_name)。部分限定名称(写为tbl_name.col_name)引用命名表中的列。非限定名称(简称为col_name)指的是周围上下文指示的任何表。
答案 1 :(得分:0)
不是这样的:
INNER JOIN [Check].[dbo].[tbl_companies] As B ON
i.CONCOM, B.company
你应该有这个:
INNER JOIN [Check].[dbo].[tbl_companies] As B ON
i.CONCOM = B.company