Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

27 员工奖金 #33

Open
astak16 opened this issue Jan 21, 2022 · 0 comments
Open

27 员工奖金 #33

astak16 opened this issue Jan 21, 2022 · 0 comments
Labels

Comments

@astak16
Copy link
Owner

astak16 commented Jan 21, 2022

题目

选出所有 bonus < 1000 员工的 name 及其 bonus

create table employee (
	empId int,
	name varchar(255),
	supervisor int,
	salary int
);
insert into employee values
(1, 'John', 3, 1000),
(2, 'Dan', 3, 1000),
(3, 'Brad', null, 1000),
(4, 'Thomas', 3, 1000);

create table bonus(
	empId int,
	bonus int
);
insert into bonus values
(2, 500),
(4, 2000);

SQL

select name, bonus from employee left join bonus on employee.empId = bonus.empId
where ifnull(bonus, 0) < 1000;

解析

employeebonus 通过 empId 左连,筛选出 bonus 小于 1000 的数据

判断 null 的方法:

  • ifnull()
  • isnull()
  • is null
@astak16 astak16 added the 简单 label Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant