我无法解决这个问题......希望有人能帮助我......我得到了这个查询:
SELECT V.ID, ....,
(SELECT SUM(D.value)
FROM E
LEFT JOIN I ON E.ID = I.f1
LEFT JOIN D ON I.f2 = D.ID
WHERE E.ID_ven = V.ID) inc
FROM ven V
WHERE V.ID=....
问题是:我必须 SUM(D.values) 但只能在 DISTINCT D.ID 值上。我试图用子查询:
SELECT V.ID,....,
(SELECT SUM(D.value) FROM (
SELECT DISTINCT D.ID, D.value
FROM E
LEFT JOIN I ON E.ID = I.f1
LEFT JOIN D ON I.f2 = D.ID
WHERE E.ID_ven = V.ID) A1 ) inc
FROM ven V WHERE V.ID=....
但是mysql给了我:错误代码:1054 Unknown column 'V.ID' in 'where Clause'