当前位置:网站首页>字节数仓实习生面试sql题
字节数仓实习生面试sql题
2022-04-23 06:15:00 【山顶看数据】
题目要求
id cnt url
1 12 a
2 21 f
1 32 e相关说明:
cnt相当于日期
这里需要把这个表拆分成如下的类型
id 最大日期 url 最小日期 url
1 32 e 12 a
当时脑子突然一热,在面试官面前有点紧张,这道题也就没有做出来,面试完之后自己又重新审视了一下这道题,具体的sql语句如下
select
t3.id,t3.cnt,t3.url,t4.cnt,t4.url
from
(select
t1.*
from
(select
id,cnt,url,row_number() over(partition by id order by cnt) temp
from info) t1
where t1.temp <2 ) t3
join
(select
t2.*
from
(select
id,cnt,url,row_number() over(partition by id order by cnt desc) temp
from info) t2
where t2.temp <2) t4
on t3.id = t4.id
这道题主要的是要把多余的列剔除掉,表中只保留最大列和最小列。
版权声明
本文为[山顶看数据]所创,转载请带上原文链接,感谢
https://blog.csdn.net/li1579026891/article/details/121769754
边栏推荐
猜你喜欢
随机推荐
Infrared sensor control switch
大型体育赛事无线通信系统
【51单片机交通灯仿真】
项目文件“ ”已被重命名或已不在解决方案中、未能找到与解决方案关联的源代码管理提供程序——两个工程问题
enforce fail at inline_ container. cc:222
“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
美摄科技云剪辑,助力哔哩哔哩使用体验再升级
Chapter 5 fundamentals of machine learning
美摄科技起诉天目传媒使用火山引擎侵权代码的声明
JDBC连接池
【点云系列】DeepMapping: Unsupervised Map Estimation From Multiple Point Clouds
[8] Assertion failed: dims.nbDims == 4 || dims.nbDims == 5
南方投资大厦SDC智能通信巡更管理系统
Unwind 栈回溯详解
城市应急管理|城市突发事故应急通信指挥调度系统
Thanos. SH kill bully script, easily delete half of the files in the system at random
海南凤凰机场智能通信解决方案
Device Tree 详解
ARMCC/GCC下的stack protector
社区版阿里MQ普通消息发送订阅Demo