Half-
Half-
全部文章
分类
题解(59)
归档
标签
去牛客网
登录
/
注册
Half-的博客
TA的专栏
45篇文章
0人订阅
sql刷题笔记
45篇文章
456人学习
全部文章
(共45篇)
题解 | #获得积分最多的人(三)#
来自专栏
思路:将上题的sum()改成sum(case when)selectid,name,grade_sumfrom( select id ,name ,sum(case when type = 'add' then grade_num else -grade_num end) g...
2021-07-28
0
414
题解 | #获得积分最多的人(二)#
来自专栏
思路:窗口函数关键:窗口函数在group by后运行,所以可以对聚合后的和进行排序selectid,namegrade_sumfrom( select id ,name ,sum(grade_num) grade_sum ,dense_rank()over(order ...
2021-07-28
0
290
题解 | #获得积分最多的人(一)#
来自专栏
selectname,sum(grade_num) grade_sumfrom user uleft join grade_info g on u.id = g.user_idgroup by 1order by 2 desclimit 1
2021-07-28
0
361
题解 | #最差是第几名(二)#
来自专栏
思路:中位数的正序>2/total,倒序>2/total(即使是累加的排名)selectgradefrom( select grade ,sum(number)over(order by grade) t_rank ,sum(number)over(order b...
2021-07-28
0
348
题解 | #实习广场投递简历分析(三)#
来自专栏
思路:分别查询后连接,用字符串方法连接,第一年的年+1 = 第二年的年,第一年的月 = 第二年的月selecta.job,first_year_mon,first_year_cnt,second_year_mon,second_year_cntfrom( select job ,d...
2021-07-28
0
321
题解 | #实习广场投递简历分析(二)#
来自专栏
思路:直接按月份分组聚合 问题:降序需要用两个desc select job ,substring(date,1,7) mon ,sum(num) cnt from resume_info where year(date) = '2025' group by 1,2 ...
2021-07-28
0
374
题解 | #牛客的课程订单分析(七)#
来自专栏
思路:由于要取出所有订单,所以用窗口函数,case when+group by 得到新列selectcase when client_name is null then 'GroupBuy' else client_name end source,count() cntfrom( select...
2021-07-27
0
365
题解 | #牛客的课程订单分析(六)#
来自专栏
select id ,is_group_buy ,client_name from ( select o.id ,is_group_buy &n...
2021-07-27
0
302
题解 | #牛客的课程订单分析(五)#
来自专栏
思路:对日期进行排序,用max(case when)转置(用sum需要转换格式) select user_id ,max(case when rk = 1 then date else 0 end) first_buy_date ,max(case when rk = 2 then date els...
2021-07-27
0
368
题解 | #牛客的课程订单分析(二)#
来自专栏
思路:count()over select id ,user_id ,product_name ,status ,client_id ,date from ( select * &...
2021-07-27
0
410
首页
上一页
1
2
3
4
5
下一页
末页