我有以下查询按预期工作:
SELECT
SERVICE_HISTORY.ServiceMode, SERVICE_HISTORY.CreatedDate,
SERVICE_HISTORY.CreatedBy, SERVICE_HISTORY.Branch,
SERVICE_HISTORY.Comments
FROM
DEBA_US.dbo.SERVICE_HISTORY
JOIN
(SELECT MAX(SERVICE_HISTORY.CreatedDate) AS maxDate, CUSTOMER.AccNo
FROM DEBA_US.dbo.CUSTOMER
INNER JOIN (DEBA_US.dbo.SERVICE_HISTORY
INNER JOIN DEBA_US.dbo.CAR ON SERVICE_HISTORY.ROW_PK = CAR.ROW_PK) ON CUSTOMER.ROW_PK = CAR.ROW_PK
WHERE
CUSTOMER.AccNo LIKE 'CUS-1234'
AND CAR.DateSubmitted IS NULL
GROUP BY
CUSTOMER.AccNo) AS testQuery ON testQuery.maxDate = SERVICE_HISTORY.CreatedDate
查询是为我提供给定客户的最新(最大)服务历史日期。
当我在 SQL Server 中执行查询时,它工作得非常好,但是当我将相同的查询放入 EXCEL 2010 (Microsoft Query) 时,它给了我错误:
没有为“testQuery”的第 1 列指定
列名无效的列名“maxDate”
无法准备语句
我无法修复查询以传递错误。有人可以告诉我为什么 Excel 不能处理上述查询吗?谢谢