文章目录
- 总结
- 1978. 上级经理已离职的公司员工
- 1990. 统计实验的数量[建立两个临时表并笛卡尔积]
- 2020. 无流量的帐户数
- 2026. 低质量的问题
- 2041. 面试中被录取的候选人
- 2051.商店中每个成员的类别
总结
多表左连接转2051题【重点】
其他待补充
1978. 上级经理已离职的公司员工
# Write your MySQL query statement below
select employee_id
from Employees
where manager_id in(
select manager_id
from Employees
where manager_id not in (select employee_id from Employees))
and salary <30000
order by employee_id
1990. 统计实验的数量[建立两个临时表并笛卡尔积]
# Write your MySQL query statement below
with new_table as(
select 'Android' platform
union select 'IOS'
union select 'Web'
),
other_table as(
select 'Reading' experiment_name
union select 'Sports'
union select 'Programming'
)
select new_table.platform ,other_table.experiment_name,count(experiment_id)num_experiments
from new_table join other_table #笛卡尔积
left join Experiments E
on E.platform = new_table.platform
AND other_table.experiment_name = E.experiment_name
group by new_table.platform ,other_table.experiment_name
提示:以下是本篇文章正文内容,下面案例可供参考
2020. 无流量的帐户数
# Write your MySQL query statement below
with new_table as(
select DISTINCT account_id from Subscriptions where
date_format(start_date,'%Y') = '2021' or
date_format(end_date,'%Y') = '2021'
)
select count(*) accounts_count
from Streams S right join new_table N
on N.account_id = S.account_id
where substring(stream_date,1,4) <> '2021'
2026. 低质量的问题
# Write your MySQL query statement below
SELECT problem_id
FROM Problems
#这里不要用round四舍五入
WHERE likes/(likes+dislikes)<0.60
order by problem_id asc
2041. 面试中被录取的候选人
# Write your MySQL query statement below
select distinct candidate_id
from Candidates C LEFT join Rounds R
on C.interview_id = R.interview_id
where years_of_exp >=2
group by C.candidate_id
having sum(score) >15
2051.商店中每个成员的类别
[题意解释:
记录买家(1表)到店次数(2表)和到店购买特定物品的次数(3表)的比值
从没有到店或者从没有该买(3表)的客户标记为: ‘Bronze’
购买过3表,但是比值小于50的客户标记为Silver’
购买过3表,但是比值大于等于50小于80的标记为’Gold’
购买过3表,且比值大于等于80的标记为’Diamond’
]
# Write your MySQL query statement below
select M.member_id,M.name,(
case
when count(V.visit_id) = 0 then 'Bronze'
when count(P.visit_id)/count(V.visit_id) < 0.5 then 'Silver'
when count(P.visit_id)/count(V.visit_id) <0.8 then 'Gold'
else 'Diamond'
end) AS category
from Members M left join Visits V
on M.member_id = V.member_id
left join Purchases P
on P.visit_id = V.visit_id
group by M.member_id