我最近將MySQL升級到了5.1.41。升級之前,以下的SQL工作(或者至少我以爲我記得它工作......自設計這個以來已經過了幾個星期......)。現在SQL給了我一個錯誤,指出「存檔」列是不明確的。我怎樣才能以不同的方式來寫,或者我還沒有意識到另一個問題?當我升級之前,MySQL正在返回一個「列模糊不清」錯誤
我只想返回「unit_id」,「lease_count」(存儲在另一個表中,其中應包含一個與「a.unit_id」對應的unit_id)和「lease_archived_count」(存儲在另一個帶有unit_id的表中)與「a.unit_id」)對應。
SELECT a.unit_id,
(SELECT count(*) FROM o_leases WHERE unit_id = a.unit_id AND archived = 0) as lease_count,
(SELECT count(*) FROM o_leases WHERE unit_id = a.unit_id AND archived = 1) as lease_archive_count
FROM p_unit a, properties b, portfolio c
WHERE a.property_id = b.properties_id
AND b.portfolio_id = c.portfolio_id
AND a.archived = 0
感謝您的幫助。
是否在多個表格(p_unit,properties,portfolio)中存檔了一列? – Tommy 2010-04-07 22:22:38