有趣的电影
题目
思路
这道题很简单,只需要满足两个条件,最后对结果按rating进行降序
只要指导where和order by的用法,就可以解决
代码
# Write your MySQL query statement below
select * from cinema
where id%2=1
and description != 'boring'
order by rating desc
平均售价
题目
思路
主要是要了解ifnull,round,between and这几个函数的用法
代码
# Write your MySQL query statement below
select p.product_id,ifnull(round(sum(u.units*p.price)/sum(u.units),2),0) as average_price
from prices as p
left join unitssold as u
on p.product_id = u.product_id
and u.purchase_date between p.start_date and p.end_date
group by p.product_id
项目员工
题目
1211. 查询结果的质量和占比 - 力扣(LeetCode)
思路
重点在于掌握函数,然后理清思路,按照题目要求限制条件即可
代码
# Write your MySQL query statement below
select query_name,
round(avg(rating/position),2) as quality,
round(sum(if(rating<3,1,0))*100/count(*),2) as poor_query_percentage
from queries
where query_name is not null
group by query_name