对于较复杂的题,按需求处理产生新表,再连接。
力扣1126:
select business_id from Events join (select event_type,avg(occurences) as avg_occurences from Events group by event_type) as tmp on Events.event_type = tmp.event_type and Events.occurences > tmp.avg_occurences group by business_id having count(*) >= 2
力扣1212:
select Teams.team_id,team_name,sum(ifnull(points,0)) as num_points from Teams left join ((select host_team, case when host_goals > guest_goals then 3 when host_goals = guest_goals then 1 else 0 end as points from Matches) union all (select guest_team, case when guest_goals > host_goals then 3 when guest_goals = host_goals then 1 else 0 end as points from Matches)) as tmp on Teams.team_id = tmp.host_team group by Teams.team_id order by num_points desc,team_id
-END
标签:tmp,join,host,goals,team,新表,综训,id,select From: https://www.cnblogs.com/peitongshi/p/16747542.html