打卡第5天 -- 3S2A1P : 三道sql,2道算法,1道简答
sql-1
https://www.nowcoder.com/practice/fc7344ece7294b9e98401826b94c6ea5?tpId=82&&tqId=29773&rp=1&ru=/ta/sql&qru=/ta/sql/question-ranking
查找所有员工自入职以来的薪水涨幅情况,给出员工编号emp_no以及其对应的薪水涨幅growth,并按照growth进行升序
(注:可能有employees表和salaries表里存在记录的员工,有对应的员工编号和涨薪记录,但是已经离职了,离职的员工salaries表的最新的to_date!='9999-01-01',这样的数据不显示在查找结果里面)
技术点:
过滤技巧:where 使用inner join 也可实现过滤
where
order by
减法:-
逻辑稍微麻烦一点
select c.emp_no,(c.salary-i.salary) as growth
from
-- 查询当前薪资
(select emp_no,salary
from salaries
where to_date='9999-01-01')as c
inner join
-- 查询入职薪资
(select s.emp_no,s.salary
from salaries as s inner join employees as e
on s.emp_no=e.emp_no and s.from_date=e.hire_date) as i
on c.emp_no=i.emp_no
order by growth
sql-2
https://www.nowcoder.com/practice/6744b90bbdde40209f8ecaac0b0516fe?tpId=82&&tqId=29800&rp=1&ru=/ta/sql&qru=/ta/sql/question-ranking
将employees表的所有员工的last_name和first_name拼接起来作为Name,中间以一个空格区分
(注:该数据库系统是sqllite,字符串拼接为 || 符号,不支持concat函数)
技术点
sql 的拼接 ( || ||)
select (last_name||' '||first_name) as Name from employees