标签:统计 条件 char 一个 span ifnull size from sql
mysql 版本:5.5.13
工资表(salary_info)
create table salary_info( name varchar(80) comment ‘员工姓名‘, salary decimal(16,2) comment ‘工资‘ )
内容
INSERT INTO `examination_questions_practice`.`salary_info` (`name`, `salary`) VALUES (‘张大胖‘, ‘10000‘); INSERT INTO `examination_questions_practice`.`salary_info` (`name`, `salary`) VALUES (‘小李‘, ‘5000‘); INSERT INTO `examination_questions_practice`.`salary_info` (`name`, `salary`) VALUES (‘王师傅‘, ‘20000‘);
name
|
salary
|
张大胖 | 10000 |
小李 | 5000 |
王师傅 | 20000 |
奖金表(bonus_info)
create table bonus_info( name varchar(80) comment ‘员工姓名‘, bonus decimal(16,2) commetn ‘奖金‘ )
内容
INSERT INTO `bonus_info` (`name`, `bonus`) VALUES (‘张大胖‘, ‘2000‘); INSERT INTO `bonus_info` (`name`, `bonus`) VALUES (‘王师傅‘, ‘3000‘);
name | bonus |
张大胖 | 2000 |
王师傅 | 3000 |
select a.name as ‘员工姓名‘, (IFNULL(a.salary,0) + IFNULL(b.bonus,0)) as ‘应发薪水‘ from salary_info a inner join bonus_info b on a.name=b.name
运行结果:
员工姓名 | 应发薪水 |
张大胖 | 12000 |
王师傅 | 23000 |
select a.name as ‘员工姓名‘, (IFNULL(a.salary,0) + IFNULL(b.bonus,0)) as ‘应发薪水‘ from salary_info a left join bonus_info b on a.name=b.name
运行结果
员工姓名 | 应发薪水 |
张大胖 | 12000 |
小李 | 5000 |
王师傅 | 23000 |
a.name | a.salary | b.name | b.bonus |
张大胖 | 10000 | 张大胖 | 2000 |
王师傅 | 20000 | 王师傅 | 3000 |
select * from salary_info a inner join bonus_info b on a.name=b.name
a.name | a.salary | b.name | b.bonus |
张大胖 | 10000 | 张大胖 | 2000 |
小李 | 5000 | null | null |
王师傅 | 20000 | 王师傅 | 3000 |
select * from salary_info a left join bonus_info b on a.name=b.name
标签:统计 条件 char 一个 span ifnull size from sql
原文地址:https://www.cnblogs.com/stone94/p/10224415.html