select AP.name , AP.201 , AP.202, AP.203, AP.204, BP.riqi , BP.sl , if(isnull(BP.riqi),null, case BP.riqi when 201 then AP.201+AP.202+AP.203+AP.204+BP.sl when 202 then AP.202+AP.203+AP.204+BP.sl when 203 then AP.203+AP.204+BP.sl when 204 then AP.204+BP.sl end ) as zongji from AP left join BP on AP.name= BP.name
select if(b.riqi=201,a.201+a.202+a.203+a.204, if(b.riqi=202,a.202+a.203+a.204, if(b.riqi=203,a.203+a.204,0))) from AP a inner join BP b on A.name= B.name
if(isnull(BP.riqi),null,
case BP.riqi
when 201 then AP.201+AP.202+AP.203+AP.204+BP.sl
when 202 then AP.202+AP.203+AP.204+BP.sl
when 203 then AP.203+AP.204+BP.sl
when 204 then AP.204+BP.sl
end
) as zongji
from AP left join BP on AP.name= BP.name
if(b.riqi=201,a.201+a.202+a.203+a.204,
if(b.riqi=202,a.202+a.203+a.204,
if(b.riqi=203,a.203+a.204,0)))
from AP a inner join BP b on A.name= B.name