赞
踩
SQL266 考试分数(一)
select job,
round(avg(score),3) as avg
from grade
group by job
order by avg desc
SQL267 考试分数(二)
select
id,
a.job,
score
from grade as a
join
(select job,avg(score) as avg_score from grade group by job) as b
on a.job=b.job
where score>avg_score
order by id
SQL268 考试分数(三)
select a.id,b.name,a.score
from language as b
join
(select id, language_id ,score,
dense_rank()over(partition by language_id order by score desc) as rk
from grade) as a
on a.language_id=b.id
where rk<=2
order by name,score desc,a.id
select id,name,score
from
(select a.id,name,score,
dense_rank()over(partition by language_id order by score desc) as rk
from grade as a
join language as b
on a.language_id=b.id) as c
where rk<=2
order by name,score desc,id
SQL269 考试分数(四)
select job,
floor(( count(*) + 1 )/ 2 ) AS "start",
floor(( count(*) + 2 )/ 2 ) AS 'end'
from grade
group by job
order by job
floor() 函数返回小于或等于指定值(value)的最小整数,取整,没有四舍五入这一说法 floor(103.56) 返回 103 floor(103.46) 返回 103
SQL270 考试分数(五)
select a.id,a.job,a.score,a.t_rank
from (
select id,job,score,
row_number()over(partition by job order by score desc) as t_rank
from grade) as a
join (
select job,
floor((count(*)+1)/2) as t_rank1,
floor((count(*)+2)/2) as t_rank2
from grade
group by job) as b
on a.job=b.job
where t_rank=b.t_rank1 or t_rank=b.t_rank2
order by id
SQL271 牛客的课程订单分析(一)
select id ,user_id,product_name,status,client_id,date
from order_info
where date>'2025-10-15' and status='completed' and product_name in ('C++','Java','Python')
order by id
SQL272 牛客的课程订单分析(二)
select user_id
from order_info
where date>'2025-10-15'
and status='completed'
and product_name in ('C++','Java','Python')
group by user_id
having count(user_id)>=2
order by user_id
SQL273 牛客的课程订单分析(三)
select *
from order_info
where date>'2025-10-15'
and status='completed'
and product_name in ('C++','Java','Python')
and user_id in (
select user_id
from order_info
where date>'2025-10-15'
and status='completed'
and product_name in ('C++','Java','Python')
group by user_id
having count(user_id)>=2
)
order by id
SQL274 牛客的课程订单分析(四)
select
user_id,
min(date) as first_buy_date,
count(user_id) as cnt
from order_info
where date > '2025-10-15'
and product_name in ('C++','Java','Python')
and status = 'completed'
group by user_id
having count(user_id) > 1
order by user_id
SQL275 生客的课程订单分析(五)
select user_id, max(case when rank_no=1 then date else 0 end) as first_buy_date, max(case when rank_no=2 then date else 0 end) as second_buy_date, cnt from (select user_id, date, row_number() over(partition by user_id order by date) as rank_no, count(*) over(partition by user_id) as cnt from order_info where date >= '2025-10-16' and status = 'completed' and product_name in('C++','Java','Python') ) as a where rank_no<=2 and cnt>=2 group by user_id,cnt order by user_id
SQL276 牛客的课程订单分析(六)
select a.id, is_group_buy, name as client_name from order_info as a left join client as b on a.client_id = b.id where date > '2025-10-15' and status = 'completed' and product_name in ('C++','Java','Python') and user_id in ( select user_id from order_info where date > '2025-10-15' and status = 'completed' and product_name in ('C++','Java','Python') group by user_id having count(status) >= 2 ) order by a.id
select b.id,b.is_group_buy,a.name as client_name
from client as a right join
(
select *,count(id) over(partition by user_id) as number
from order_info
where datediff(date,"2025-10-15")>0
and status="completed"
and product_name in ("C++","Java","Python")
) as b
on a.id=b.client_id
where b.number >1
order by b.id
SQL277 牛客的课程订单分析(七)
select if(a.client_id = 0, 'GroupBuy', c.name) as source, count(*) as cnt from order_info as a left join client as c on a.client_id = c.id where a.status = 'completed' and a.date >= '2025-10-15' and a.product_name in ('C++', 'Java', 'Python') and user_id in ( select user_id from order_info as a where a.status = 'completed' and a.date >= '2025-10-15' and a.product_name in ('C++', 'Java', 'Python') group by user_id having count(*) > 1 ) group by a.client_id order by source
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。