select t3.companyId,t3.companyName as companyName , t1.coachNum, t2.guideNum, t3.playerNum , IFNULL(t1.coachNum,0) + IFNULL(t2.guideNum,0) + IFNULL(t3.playerNum,0) as sum from
select t3.companyId,t3.companyName as companyName , t1.coachNum, t2.guideNum, t3.playerNum , IFNULL(t1.coachNum,0) + IFNULL(t2.guideNum,0) + IFNULL(t3.playerNum,0) as sum
(select t.companyId, t.companyName,count(t.id) as playerNum from
(SELECT
DISTINCT(tcp.id) as id, tcc.id as companyId,tcc.`name` as companyName
FROM
FROM
t_compete_company tcc
(
left join
SELECT
t_compete_player tcp on tcc.id = tcp.company_id
t.companyId,
LEFT JOIN t_compete_project_player tcpp ON tcp.id = tcpp.player_id
t.companyName,
WHERE
count( t.id ) AS playerNum
tcc.type = 0
FROM
AND tcp.company_id = tcc.id
(
AND tcc.rec_status = 0
SELECT DISTINCT
AND tcp.rec_status = 0
( tcp.id ) AS id,
AND tcpp.rec_status = 0
tcc.id AS companyId,
UNION
tcc.`name` AS companyName
SELECT
FROM
DISTINCT(tcp.id) as id,tcc.id as companyId,tcc.`name` as companyName
t_compete_company tcc
FROM
LEFT JOIN t_compete_player tcp ON tcc.id = tcp.company_id AND tcp.rec_status = 0
t_compete_company tcc
LEFT JOIN t_compete_project_player tcpp ON tcp.id = tcpp.player_id AND tcpp.rec_status = 0
LEFT JOIN t_compete_team tct ON tcc.id = tct.company_id
WHERE
LEFT JOIN t_compete_team_member tctm on tct.id = tctm.compete_team_id
tcc.type = #{competeTimeId}
LEFT JOIN t_compete_player tcp ON tctm.player_id = tcp.id
AND tcc.rec_status = 0
WHERE
UNION
tcc.type = 0
SELECT DISTINCT
AND tct.rec_status = 0
( tcp.id ) AS id,
AND tctm.rec_status = 0
tcc.id AS companyId,
And tcc.rec_status = 0
tcc.`name` AS companyName
AND tcp.rec_status = 0) t
FROM
group by t.companyId
t_compete_company tcc
having count(t.id) > 0
LEFT JOIN t_compete_team tct ON tcc.id = tct.company_id AND tct.rec_status = 0
) t3
LEFT JOIN t_compete_team_member tctm ON tct.id = tctm.compete_team_id AND tctm.rec_status = 0
left join
LEFT JOIN t_compete_player tcp ON tctm.player_id = tcp.id AND tcp.rec_status = 0
(SELECT tcc.id as companyId,tcc.`name` as companyName ,count(tcca.id) as coachNum FROM t_compete_company tcc left join (select * from t_compete_coach where rec_status = 0) tcca on tcc.id = tcca.company_id where tcc.type = 0 AND identity = 1 and tcc.rec_status = 0 GROUP BY tcc.id) t1 on t1.companyId = t3.companyId
WHERE
left join
tcc.type = #{competeTimeId}
(SELECT tcc.id as companyId,tcc.`name` as companyName , count(tcca.id) as guideNum FROM t_compete_company tcc left join (select * from t_compete_coach where rec_status = 0) tcca on tcc.id = tcca.company_id where tcc.type = 0 AND identity = 0 and tcc.rec_status = 0 GROUP BY tcc.id) t2 on t2.companyId = t3.companyId
AND tct.rec_status = 0
) t
GROUP BY
t.companyId
HAVING
count( t.id ) > 0
) t3
LEFT JOIN (
SELECT
tcc.id AS companyId,
tcc.`name` AS companyName,
count( tcca.id ) AS coachNum
FROM
t_compete_company tcc
LEFT JOIN ( SELECT * FROM t_compete_coach WHERE rec_status = 0 ) tcca ON tcc.id = tcca.company_id
AND tcca.rec_status = 0
WHERE
tcc.type = #{competeTimeId}
AND identity = 1
AND tcc.rec_status = 0
GROUP BY
tcc.id
) t1 ON t1.companyId = t3.companyId
LEFT JOIN (
SELECT
tcc.id AS companyId,
tcc.`name` AS companyName,
count( tcca.id ) AS guideNum
FROM
t_compete_company tcc
LEFT JOIN ( SELECT * FROM t_compete_coach WHERE rec_status = 0 ) tcca ON tcc.id = tcca.company_id