我得到錯誤#1054 - 未知列'e.ProjectID「的條款」與下面的SQL#1054 - 未知列'e.ProjectID「的條款」
SELECT ProjectID
FROM Project as p
INNER JOIN (SELECT EquipID , EquipName , EquipTypeID , (EquipPrice*Quantity) As CstAmount FROM Equipment) as e
ON p.ProjectID=e.ProjectID
我得到錯誤#1054 - 未知列'e.ProjectID「的條款」與下面的SQL#1054 - 未知列'e.ProjectID「的條款」
SELECT ProjectID
FROM Project as p
INNER JOIN (SELECT EquipID , EquipName , EquipTypeID , (EquipPrice*Quantity) As CstAmount FROM Equipment) as e
ON p.ProjectID=e.ProjectID
你的子查詢沒有將該列暴露給外部查詢。
SELECT ProjectID
FROM Project As p
INNER
JOIN (
SELECT ProjectID
, EquipID
, EquipName
, EquipTypeID
, (EquipPrice*Quantity) As CstAmount
FROM Equipment
) As e
ON p.ProjectID = e.ProjectID
不過,如果你只是想返回專案編號話,我建議你執行這個查詢,而不是:
SELECT ProjectID
FROM Project
WHERE EXISTS (
SELECT *
FROM Equipment
WHERE ProjectID = Project.ProjectID
)
爲什麼你需要子查詢?看着他的查詢,它看起來很簡單內部加入 – DevelopmentIsMyPassion
你不需要任何的子查詢。剛剛加入的項目表,設備表如下
SELECT p.ProjectID,e.EquipID ,e.EquipName ,e.EquipTypeID ,e.EquipPrice* e.Quantity as CstAmount from Project P join Equipment e on p.ProjectID=e.ProjectID
,你可以做到這一點沒有子查詢
SELECT p.ProjectID ,e.EquipID , e.EquipName , e.EquipTypeID , (e.EquipPrice * e.Quantity) As CstAmount
FROM Project as p
INNER JOIN Equipment as e
ON p.ProjectID= e.ProjectID
你會得到一個錯誤,因爲兩個表中都存在ProjectID。在SELECT中添加前綴 – Pascamel
什麼是你想怎麼辦?查詢可改寫像下面,但我懷疑這是你想要
SELECT p.ProjectID
FROM Project as p
INNER JOIN Equipment as e
ON p.ProjectID = e.ProjectID
你需要選擇你的子查詢的領域以及哪些?
在子查詢中添加'ProjectID'。 –
請制定一個實際的問題,與一段代碼相關,你也應該發佈 – bottleboot
實際上你不需要子查詢,因爲你只需要'ProjectID'。 –