2013-08-27 83 views
0

我正在嘗試生成顯示計算機時代的報告。MySQL - 未知列字段列表

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' 在 '字段列表'

+0

請注意,「WHERE M.CS_MANUFACTURER LIKE'%dell%'」無法使用索引 – Strawberry

回答

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 
+0

這有效。 @ user1281385的建議也起作用。 – user2721898

1

你應該使用

MAX(END_DATE) as END_DATE 

當你定義它

相關問題