sql如何对列中的部分数据做统计,结果显示在其它列。
以下是想要的结果

我的sql代码
select year,cecp_id,my_type,totalCount,completeCount,unCompleteCount,completePercent,concat(TRUNCATE(completeCount/totalCount * 100,1) ,'%') from
(
SELECT year,cecp_id,my_type,COUNT(1) totalCount,SUM(status=1) completeCount,SUM(status=0) unCompleteCount,CONCAT(TRUNCATE(SUM(status=1)/COUNT(1) * 100,1) ,'%') completePercent FROM
(SELECT Year(t2.created) year,my_type,cecp_id,status
FROM
(SELECT created,cecp_id,ceci_id,ns_box ,my_type ,cecc.id cecc_id
FROM
(select cecp.created,cecp.id cecp_id,ceci.id ceci_id,ns_box ,ceci.`type` my_type
FROM corp_equipment_check_plan cecp
inner join corp_equipment_check_item ceci on cecp.id = ceci.corp_equipment_check_plan_id) t1
inner join corp_equipment_check_circle cecc on cecc.corp_equipment_check_plan_id = t1.cecp_id) t2
inner join corp_equipment_check_circle_item cecci on t2.cecc_id = cecci.corp_equipment_check_circle_id AND
t2.cecp_id = cecci.corp_equipment_check_plan_id AND t2.ceci_id = cecci.corp_equipment_check_item_id
where my_type = 0
)t3 group by cecp_id
union all
SELECT year,cecp_id,my_type,COUNT(1) totalCount,SUM(status=1) completeCount,SUM(status=0) unCompleteCount,CONCAT(TRUNCATE(SUM(status=1)/COUNT(1) * 100,1) ,'%') completePercent FROM
(SELECT Year(t2.created) year,my_type,cecp_id,status
FROM
(SELECT created,cecp_id,ceci_id,ns_box ,my_type ,cecc.id cecc_id
FROM
(select cecp.created,cecp.id cecp_id,ceci.id ceci_id,ns_box ,ceci.`type` my_type
FROM corp_equipment_check_plan cecp
inner join corp_equipment_check_item ceci on cecp.id = ceci.corp_equipment_check_plan_id) t1
inner join corp_equipment_check_circle cecc on cecc.corp_equipment_check_plan_id = t1.cecp_id) t2
inner join corp_equipment_check_circle_item cecci on t2.cecc_id = cecci.corp_equipment_check_circle_id AND
t2.cecp_id = cecci.corp_equipment_check_plan_id AND t2.ceci_id = cecci.corp_equipment_check_item_id
where my_type = 1
)t3 group by cecp_id
union all
SELECT year,cecp_id,my_type,COUNT(1) totalCount,SUM(status=1) completeCount,SUM(status=0) unCompleteCount,CONCAT(TRUNCATE(SUM(status=1)/COUNT(1) * 100,1) ,'%') completePercent FROM
(SELECT Year(t2.created) year,my_type,cecp_id,status
FROM
(SELECT created,cecp_id,ceci_id,ns_box ,my_type ,cecc.id cecc_id
FROM
(select cecp.created,cecp.id cecp_id,ceci.id ceci_id,ns_box ,ceci.`type` my_type
FROM corp_equipment_check_plan cecp
inner join corp_equipment_check_item ceci on cecp.id = ceci.corp_equipment_check_plan_id) t1
inner join corp_equipment_check_circle cecc on cecc.corp_equipment_check_plan_id = t1.cecp_id) t2
inner join corp_equipment_check_circle_item cecci on t2.cecc_id = cecci.corp_equipment_check_circle_id AND
t2.cecp_id = cecci.corp_equipment_check_plan_id AND t2.ceci_id = cecci.corp_equipment_check_item_id
where my_type = 2
)t3 group by cecp_id order by cecp_id , my_type )t4
数据库运行sql后的结果

totalCompletePercent应该是相同cecp_id的数据,它们的completeCount 和 totalCount的比值。
例如cecp_id=252,totalCompletePercent = 58+0+0/340+20+10 =15.6%,15.6%显示在这三条数据的totalCompletePercent列。