刚才帮一同事处理一条很复杂的sql 用到了sum(if),具体的sql是
SELECT
sum(if(isinner=1,1,0 )) AS innerlinktotal,
sum(if(isinner=0,1,0 )) AS outlinktotal,
sum(if(isinner=1,sitmeta.down_size,0)) AS innerlinksize,
sum(if(isinner=0,sitmeta.down_size,0)) AS outlinksize,
(sum(if(isinner=1,1,0 )) + sum(if(isinner=0,1,0 ))) AS total,
concat_ws(
ascription.operation,
`ascription`.`location`,
ascription.system
) AS belong
FROM
sitemeta_webkit_1490 AS sitmeta
LEFT JOIN domain_ascription_wwwiqiyicom AS ascription ON sitmeta.domain = ascription.domain
GROUP BY
ascription.location,
ascription.operation,
ascription.system;
记录下来 方便以后翻阅