0

我正在尝试制作一份显示计算机时代的报告。

SELECT 
M.NAME AS MACHINE_NAME, 
M.CS_MODEL AS MODEL, 
DA.SERVICE_TAG, 
DA.SHIP_DATE,
M.USER_LOGGED AS LAST_LOGGED_IN_USER, 
DW.SERVICE_LEVEL_CODE, 
DW.SERVICE_LEVEL_DESCRIPTION, 
DW.END_DATE AS EXPIRATION_DATE 
FROM MACHINE M 
JOIN DELL_ASSET DA ON (M.BIOS_SERIAL_NUMBER = DA.PARENT_SERVICE_TAG OR M.BIOS_SERIAL_NUMBER = DA.SERVICE_TAG) 
JOIN (SELECT SERVICE_TAG, SERVICE_LEVEL_CODE, SERVICE_LEVEL_DESCRIPTION, MAX(END_DATE) from DELL_WARRANTY group by SERVICE_TAG, SERVICE_LEVEL_CODE, SERVICE_LEVEL_DESCRIPTION) DW ON DW.SERVICE_TAG = DA.SERVICE_TAG 
WHERE M.CS_MANUFACTURER LIKE '%dell%' 
AND M.BIOS_SERIAL_NUMBER!='' 
AND DA.DISABLED != 1 
AND DW.END_DATE < NOW()
AND DW.SERVICE_TAG IS NULL
;

上面的代码会产生这个错误。我究竟做错了什么?

块引用

错误代码:1054。“字段列表”中的未知列“DW.END_DATE”

4

2 回答 2

1

你应该使用

MAX(END_DATE) as END_DATE

当你定义它时

于 2013-08-27T14:57:14.477 回答
0

您需要在子查询中为MAX(END_DATE)计算字段添加别名。

JOIN (SELECT    SERVICE_TAG
                , SERVICE_LEVEL_CODE
                , SERVICE_LEVEL_DESCRIPTION
                , MAX(END_DATE) AS END_DATE
        from    DELL_WARRANTY 
        group by
                SERVICE_TAG
                , SERVICE_LEVEL_CODE
                , SERVICE_LEVEL_DESCRIPTION) DW 
ON  DW.SERVICE_TAG = DA.SERVICE_TAG 
于 2013-08-27T14:58:00.980 回答