SELECT IFNULL( c.compId, '1' ) compId, c.compShortName, IFNULL( c.compCompID, '' ) compCompID, IFNULL( c.compName, '未绑定单位' ) compName, COUNT( CASE WHEN checkType = '1' THEN 1 END ) AS jsCount, COUNT( CASE WHEN checkType = '0' THEN 1 END ) AS count, d.compName compCompName FROM checkinfo b LEFT JOIN companyinfo c ON b.checkCompanyId = c.compId LEFT JOIN companyinfo d ON c.compCompId = d.compId WHERE b.STATUS = '1' -- AND c.compName != '未绑定单位' GROUP BY c.compId, checkType ORDER BY count( checkId ) DESC 怎样优化
理解问题SELECT IFNULL( c.compId, '1' ) compId, c.compShortName, IFNULL( c.compCompID, '' ) compCompID, IFNULL( c.compName, '未绑定单位' ) compName, COUNT( CASE WHEN checkType = '1' THEN 1 END ) AS jsCount, COUNT( CASE WHEN checkType = '0' THEN 1 END ) AS count, d.compName compCompName FROM checkinfo b LEFT JOIN companyinfo c ON b.checkCompanyId = c.compId LEFT JOIN companyinfo d ON c.compCompId = d.compId WHERE b.STATUS = '1' -- AND c.compName != '未绑定单位' GROUP BY c.compId, checkType ORDER BY count( checkId ) DESC 怎样优化
已完成理解「SELECT IFNULL( c.compId, '1' ) compId, c.compShortName, IFNULL( c.compCompID, '' ) compCompID, IFNULL( c.compName, '未绑定单位' ) compName, COUNT( CASE WHEN checkType = '1' THEN 1 END ) AS jsCount, COUNT( CASE WHEN checkType = '0' THEN 1 END ) AS count, d.compName compCompName FROM checkinfo b LEFT JOIN companyinfo c ON b.checkCompanyId = c.compId LEFT JOIN companyinfo d ON c.compCompId = d.compId WHERE b.STATUS = '1' -- AND c.compName != '未绑定单位' GROUP BY c.compId, checkType ORDER BY count( checkId ) DESC 怎样优化」
展开阅读网页