php case when

select
a.openid as openid, sum( a.calorie + b.calorie)
as calorie,
(CASE WHEN a.date > b.date
THEN a.imgurl
ELSE b.imgurl
END) imgurl,
(CASE WHEN a.date > b.date
THEN a.nickname
ELSE b.nickname
END) nickname
from `spinningame` a left join `instructorinfo` b on a.openid = b.openid where a.openid = b.openid group by a.openid;

原文地址:https://www.cnblogs.com/nullman/p/8109646.html