题目链接:点击打开链接
题目大意:略。
解题思路:此题难点在于都为 ‘both’ 的时候,怎么去筛选这个 ‘both’ 很容易错误思维会把 ‘both’ 为空的情况忽略掉。
AC 代码
selectspend_date, platform, ifnull(sum(total_am),0) total_amount, ifnull(sum(total_u),0) total_usersfrom( selectp.spend_date, p.platform, t.total_am, t.total_ufrom ( selectdistinctspend_date, "desktop"platformfromSpendingunionselectdistinctspend_date, "mobile"platformfromSpendingunionselectdistinctspend_date, "both"platformfromSpending ) pleftjoin ( selectspend_date, if(count(distinctplatform)=1, platform, 'both') plat, sum(amount) total_am, count(distinctuser_id) total_ufromSpendinggroupbyspend_date, user_id ) tonp.platform=t.platandp.spend_date=t.spend_date) tempgroupbyspend_date, platform