码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Leetcode力扣 MySQL数据库 1907 按分类统计薪水


    1907 按分类统计薪水

    SQL架构

    1. Create table If Not Exists Accounts_1907 (account_id int, income int);
    2. Truncate table Accounts_1907;
    3. insert into Accounts_1907 (account_id, income) values ('3', '108939');
    4. insert into Accounts_1907 (account_id, income) values ('2', '12747');
    5. insert into Accounts_1907 (account_id, income) values ('8', '87709');
    6. insert into Accounts_1907 (account_id, income) values ('6', '91796');


    表: Accounts

    +-------------+------+
    | 列名        | 类型  |
    +-------------+------+
    | account_id  | int  |
    | income      | int  |
    +-------------+------+
    account_id 是这个表的主键。
    每一行都包含一个银行帐户的月收入的信息。
    写出一个 SQL 查询,来报告每个工资类别的银行账户数量。 工资类别如下:

    “低薪”:所有工资严格低于20000美元。
    “中等薪水”:包含范围内的所有工资 [$20000, $50000]。
    “高薪”:所有工资严格大于50000美元。

    结果表必须包含所有三个类别。 如果某个类别中没有帐户,则报告 0。

    按任意顺序返回结果表。

    查询结果格式如下示例:

    Accounts 表:
    +------------+--------+
    | account_id | income |
    +------------+--------+
    | 3          | 108939 |
    | 2          | 12747  |
    | 8          | 87709  |
    | 6          | 91796  |
    +------------+--------+

    Result 表:
    +----------------+----------------+
    | category       | accounts_count |
    +----------------+----------------+
    | Low Salary     | 1              |
    | Average Salary | 0              |
    | High Salary    | 3              |
    +----------------+----------------+

    低薪: 数量为 2.
    中等薪水: 没有.
    高薪: 有三个账户,他们是 3, 6和 8.

    解题

    1. select 'low salary' category, count(account_id) accounts_count from Accounts_1907 ac where income < 20000
    2. union
    3. select 'average salary' category, count(account_id) accounts_count from Accounts_1907 ac where income between 20000 and 50000
    4. union
    5. select 'high salary' category, count(account_id) accounts_count from Accounts_1907 ac where income > 50000;
  • 相关阅读:
    deeplab v3+ 源码详解
    1.1.C++项目:仿muduo库实现并发服务器之any类的设计
    戏说领域驱动设计(三)——困境
    10.26课上)计数排序,分割字符串
    docker系列(1) - docker环境篇
    【选择排序算法详解】Java/Go/Python/JS/C 不同语言实现
    面了个腾讯30k+出来的,他让我见识到什么叫精通MySQL调优
    什么是SpringMVC?SpringMVC之hello.jsp实现过程 问题:SpringMVC在JSP页面取不到ModelAndView中的值(已解决)
    C现代方法(第7章)笔记——基本类型
    axios发post请求,后端接收不到参数的原因及解决
  • 原文地址:https://blog.csdn.net/m0_46458212/article/details/127957610
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | 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号