码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • HIVE-SQL基础面试题(很多基础写不出来)


    题1:编写SQL拉取存在连续4天的用户
    数据源表:active_info
    字段:userid(用户id),ftime(活跃日期)
    字段样例:

    user_idftime
    1232022-07-10
    2342022-07-12

    SOL返回字段:userid

    答案

    select distinct userid
    from 
    (	-- 添加排序序号
    	select userid
    		,row_number over(partition by userid order by ftime asc) as rnk 
    		,ftime
    	from (select userid,ftime from active_info group by userid,ftime) t -- 去重
    ) t1 
    group by user_id,date_sub(ftime,rnk)
    having count(1) >= 4 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    题2:如下几段SQL分别返回什么
    数仓,数分相关工作经验,最近在面试招聘,3-8年工作经验,这三条返回全写对,10人不超过2人;
    表:ta

    id
    1
    2
    4
    null

    表:tb

    id
    2
    2
    4
    3
    • 语句1:
    select ta.id, tb.id as id2 from ta left join tb on ta.id = tb.id and tb.id > 2
    
    • 1

    答案

    idid2
    44
    1null
    2null
    nullnull
    • 语句2:
    select ta.id, tb.id as id2 from ta left join tb on ta.id = tb.id and ta.id < 3
    
    • 1

    答案

    idid2
    22
    22
    1null
    4null
    nullnull
    • 语句3:
    select ta.id,tb.id as id2 from ta full join tb on ta.id = tb.id where ta.id is null
    
    • 1

    答案

    idid2
    null3
    nullnull

    题3:编写SQL拉收6月专业公司为A、B、C的(只要这三个公司)
    比较简单的一个行转列问题
    小R用户数(月付费:[0.100)),
    中R用户数 (月付费:[100,200)),
    大R用户数 (月付费:[200,+∞))

    表名:pay_info
    字段
    专业公司:business_cd
    付费日期:statis_date(样式:2022-07-01)
    付费金额:Pay
    用户id:user_id

    SQL返回字段(4个字段):
    business_cd专公司,
    large_pay_uv大R用户数,
    mid_pay_uv中R付费用户数,
    small_pay_uv小R付费用户数

    答案

    select business_cd
    	,count(case when pay < 100 then 1 end) as small_pay_uv  -- 小R付费用户
    	,count(case when pay >= 100 and pay < 200 then 1 end) as mid_pay_uv
    	,count(case when pay >= 200 then 1 end) as large_pay_uv
    from 
    (	-- 先按专业公司,用户id对付费求和加总
    	select business_cd
    		,user_id
    		,sum(pay) as pay
    	from pay_info
    	where month(statis_date)= '6' and business_cd in ('A','B','C')
    	group by business_cd,user_id
    ) t 
    group by business_cd
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
  • 相关阅读:
    Unity 热更--AssetBundle学习笔记 1.0【AB包资源加载工具类的实现】
    Navicat的使用--mysql
    表达矩阵任意两个基因相关性分析 批量相关性分析 tcga geo 矩阵中相关性强的基因对 基因相关性
    c++中的特殊类设计
    2分钟搭建FastGPT训练企业知识库AI助理(Docker部署)
    【GEE】8、Google 地球引擎中的时间序列分析【时间序列】
    路径某个位置更换名称-python
    01-Java的static关键字、单例、代码块、继承
    如何在Windows 10/11中重置网络,以及重置后的注意事项有哪些
    局域网靶机渗透操作指南
  • 原文地址:https://blog.csdn.net/me_to_007/article/details/126328183
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号