Ai
1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-1907.test 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
# $1907. 按分类统计薪水
# https://leetcode.cn/problems/count-salary-categories/
# SQL架构
Create table If Not Exists Accounts (account_id int, income int);
Truncate table Accounts;
insert into Accounts (account_id, income) values ('3', '108939');
insert into Accounts (account_id, income) values ('2', '12747');
insert into Accounts (account_id, income) values ('8', '87709');
insert into Accounts (account_id, income) values ('6', '91796');
# Write your MySQL query statement below
select
t.category,
ifnull(a.cnt, 0) as accounts_count
from
(
select
'Low Salary' as category
union
select
'Average Salary'
union
select
'High Salary'
) t
left join (
select
case
when income < 20000 then 'Low Salary'
when income > 50000 then 'High Salary'
else 'Average Salary'
end as category,
count(*) as cnt
from
Accounts
group by
category
) a on t.category = a.category;
# clean-up
drop table Accounts;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

搜索帮助