码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 2308,2314,2324,2329,2339,2346



    文章目录

    • 2308. Arrange Table by Gender
    • 2314. The First Day of the Maximum Recorded Degree in Each City
    • 2324. Product Sales Analysis IV
    • 2329. 产品销售分析Ⅴ
    • 2339. All the Matches of the League
    • 2346. Compute the Rank as a Percentage
    • 总结


    2308. Arrange Table by Gender

    在这里插入图片描述
    在这里插入图片描述

    # Write your MySQL query statement below
    select user_id,gender
    from(
    select* ,
    #对相同性别按照id升序进行排名
    row_number()over(partition by gender order by user_id) same_rk,
    case
        when gender ='female' then 1
        when gender = 'male' then 3
        else  2
        end diff_rk
    from Genders)new_table
    order by same_rk,diff_rk
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    2314. The First Day of the Maximum Recorded Degree in Each City

    在这里插入图片描述

    with new_table as(
    select city_id,day,degree,
        rank()over(partition by city_id order by degree desc, day asc) rk
    from Weather)
    
    select city_id,day,degree
    from new_table
    where rk = 1
    order by city_id 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    2324. Product Sales Analysis IV

    在这里插入图片描述
    在这里插入图片描述

    # Write your MySQL query statement below
    with new_tale as(
        select user_id ,S.product_id ,
        RANK()OVER(PARTITION BY user_id order by  sum(quantity*price) desc)rk
        from Sales S left join Product P 
        on S.product_id = P.product_id
        group by S.user_id ,S.product_id
    )
    SELECT user_id ,product_id
    from new_tale
    where rk = 1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    2329. 产品销售分析Ⅴ

    在这里插入图片描述
    在这里插入图片描述

    # Write your MySQL query statement below
    # Write your MySQL query statement below
    with new_tale as(
        select user_id ,S.product_id ,sum(quantity*price) spending
        from Sales S left join Product P 
        on S.product_id = P.product_id
        group by user_id
    )
    SELECT user_id ,spending
    from new_tale
    order by spending desc ,1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    2339. All the Matches of the League

    在这里插入图片描述

    # Write your MySQL query statement below
    select t1.team_name home_team ,t2.team_name away_team
    from Teams t1,Teams t2
    where t1.team_name <>t2.team_name
    
    • 1
    • 2
    • 3
    • 4

    2346. Compute the Rank as a Percentage

    在这里插入图片描述
    在这里插入图片描述

    # Write your MySQL query statement below
    select student_id,department_id,
           ifnull(round((((rank()
    over(partition by department_id order by mark desc))-1)*100)
           /(count(*)over(partition by department_id)-1
           ),2),0) percentage
    from students
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    总结

    注意order by a,b
    表示先用a排序,在a排序的基础上再用b规则进行一次排序

  • 相关阅读:
    【牛客网】斐波那契数列
    【JavaScript】浏览器支持ES6和使用export import语法
    Atomic原子类详解
    【Ubuntu 20.04 LTS】安装Docker引擎
    【微前端】single-spa 到底是个什么鬼
    什么是残差网络结构
    YOLO系列改进:YOLOv5改进之strSPPF
    QT 联合opencv 易错点
    “九韶杯”河科院程序设计协会第一届程序设计竞赛题目分析以及总结
    Flink学习之旅:(三)Flink源算子(数据源)
  • 原文地址:https://blog.csdn.net/weixin_45646601/article/details/127599602
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | 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号