码农知识堂 - 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规则进行一次排序

  • 相关阅读:
    (详细步骤和代码)利用A100 GPU加速Tensorflow
    毅速丨模具3D打印材料有哪些选择
    SpringBoot整合knife 4j
    仿热血江湖游戏类43
    Bootstrap Table pagelist设置后失效
    适用于 Linux 的 WPF:Avalonia
    1521_AURIX TC275 FPI总线系统寄存器
    gpu cuda矩阵转置
    软件设计——面向对象的七大原则
    关起门来搞开源,做不了开源世界的Leader
  • 原文地址: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号