顺丰2109

一、
顺丰2109_第1张图片

select a.userid, a.paper, a.entertainment, a.food, b.class
from
(select userid,
    sum(if(class='文件', count, 0)) as paper,
    sum(if(class='娱乐', count, 0)) as entertainment,
    sum(if(class='', count, 0)) as food,
    max(count) as most_class
from(
	select userid, class, count(*) as count
	from waybill_constype
	where month(consign_day)=4
	group by userid, class
) as a
group by userid
) as a
left join 
	(select userid, class, count(*) as count
	from waybill_constype
	where month(consign_day)=4
	group by userid, class) as b
on a.userid=b.userid and a.most_class=b.count

二、
顺丰2109_第2张图片

select a.task_no, sum(transfer_fee) as total_transfer_fee
from task_arrive_transfer as a 
join task_operate as b
on a.task_no=b.task_no and month(b.start_time)=8
    and a.arrive_time between b.start_time and b.end_time
group by a.task_no

你可能感兴趣的:(数据分析笔试SQL)