代码拉取完成,页面将自动刷新
# $1126. 查询活跃业务
# https://leetcode-cn.com/problems/active-businesses/
# SQL架构
Create table If Not Exists Events (business_id int, event_type varchar(10), occurences int);
Truncate table Events;
insert into Events (business_id, event_type, occurences) values ('1', 'reviews', '7');
insert into Events (business_id, event_type, occurences) values ('3', 'reviews', '3');
insert into Events (business_id, event_type, occurences) values ('1', 'ads', '11');
insert into Events (business_id, event_type, occurences) values ('2', 'ads', '7');
insert into Events (business_id, event_type, occurences) values ('3', 'ads', '6');
insert into Events (business_id, event_type, occurences) values ('1', 'page views', '3');
insert into Events (business_id, event_type, occurences) values ('2', 'page views', '12');
# Write your MySQL query statement below
select
e1.business_id
from
Events e1
join (
select
event_type,
avg(occurences) as eventavg
from
Events
group by
event_type
) e2 on e1.event_type = e2.event_type
where
e1.occurences > e2.eventavg
group by
e1.business_id
having
count(*) >= 2;
# clean-up
drop table Events;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。