我想从每个项目中提取所有客户的报价,如果他们有多个报价,我想要平均值。
我有以下查询:
SELECT
@projectid := projects.id AS projectid,
(SELECT
SUM(`offers`) FROM
(SELECT AVG( `price` ) AS `offers`
FROM `sales`
WHERE `sales`.`projectid` = @projectid
AND `sales`.`active` = 'yes'
GROUP BY `sales`.`clientid`
) AS `average`
) AS `outstanding`
FROM projects
WHERE
projects.active = 'yes'
ORDER BY outstanding ASC
我的问题是@projectid没有传递到子查询中,我不明白我应该如何解决这个问题。
谁能给我一些建议?