SELECT
p.project_id as projectId,
p.project_name AS projectName,
COALESCE(SUM(ci.fitted_capacity),0) AS value
FROM
ees_project p
LEFT JOIN (
SELECT
cit.project_id,
cit.fitted_capacity,
cit.created_date
FROM
ees_project_cities cit
WHERE
cit.del_flag = #{delFlag}
) ci ON p.project_id = ci.project_id
WHERE
p.del_flag = #{delFlag}
<if test="startDate!=null"> AND ci.bill_date >=#{startDate}</if>
<if test="endDate!=null"> AND ci.bill_date <=#{endDate}</if>
GROUP BY p.project_name, p.project_id
ORDER BY COALESCE(SUM(ci.fitted_capacity),0) DESC
|