SQL245 查找字符串中逗号出现的次数
select
id,
length(string)-length(replace(string,",","")) as cnt
from strings
SQL246 获取emplovees中的frst name
select first_name
from employees
order by substring(first_name,-2)
SQL247 按照dept no进行汇总
select
dept_no,
group_concat(emp_no) as employees
from dept_emp
group by dept_no
SQL248 平均工资
select
avg(a.salary) as avg_salary
from salaries as a
where a.to_date = '9999-01-01' and a.salary not in
((select max(b.salary) from salaries as b where b.to_date = '9999-01-01'),
(select min(c.salary) from salaries as c where c.to_date = '9999-01-01'))
SQL249 分页查询employees表,每5行一页,返回第2页的数据
select *
from employees
limit 5,5
select *
from employees
limit 5
offset 5
SQL251 使用含有关键字exists查找未分配具体部门的员工的所有信息
select *
from employees as e
where not exists(
select emp_no from dept_emp where emp_no=e.emp_no
)
SQL253 获取有奖金的员工相关信息
select
emp_no,
first_name,
last_name,
btype,
salary,
round((case btype
when 1 then salary*0.1
when 2 then salary*0.2
when 3 then salary*0.3
end) ,1)as bonus
from employees
join emp_bonus using(emp_no)
join salaries using(emp_no)
where to_date = '9999-01-01'
order by emp_no
SQL254 统计salarv的罗计和running total
select
emp_no,
salary,
sum(salary)over(order by emp_no)as running_total
from salaries
where to_date = '9999-01-01'
SQL255 给出employees表中排名为奇数行的first name
select
first_name
from
employees as a
where(
select count(*) from employees as b
where a.first_name>=b.first_name
)%2 = 1
SQL256 出现三次以上相同积分的情况
select
number
from grade
group by number
having count(number)>=3