牛客网SQL试题库(简单)

在这里插入图片描述

SQL2:查找入职时间较晚(排名倒数第三)的员工所有信息

//方法一
select * from employees
order by hire_date DESC
limit 2,1

//方法二
select * from employees 
where hire_date = (
    select distinct hire_date from employees order by hire_date desc limit 2,1
)

分析:

distinct 排除了入职时间重复的行
order by hire_date desc 根据入职日期降序,入职晚的排在前面
limit 2,1 第三页,每页1行

limit

  • 如果给定两个参数,第一个参数指定第一个返回记录行的偏移量,第二个参数指定返回记录行的最大数目。
  • SELECT * FROM table LIMIT 5,10; // 检索记录行 6-15 ,从第6行往后显示10个

SQL4:查找所有已经分配部门的员工

where语句进行多表查询

select employees.last_name,employees.first_name,dept_emp.dept_no
from employees,dept_emp
WHERE employees.emp_no = dept_emp.emp_no

SQL7:查找薪水记录超过15次的员工号emp_no以及其对应的记录次数t

题目地址

select emp_no,count(*) t
from salaries
GROUP BY emp_no
HAVING t>15

SQL8:请你找出所有员工具体的薪水salary情况,对于相同的薪水只显示一次,并按照逆序显示

select distinct salary
from salaries
where to_date='9999-01-01'
ORDER by salary desc;

SQL10 获取所有非manager的员工emp_no

题目地址

select emp_no
from employees
where emp_no not in (select emp_no from dept_manager)

删除emp_no重复的记录,只保留最小的id对应的记录

删除表中的重复记录

错误写法,不允许在查找表的同时删除数据

delete from titles_test 
where id not in(
            select min(id)
            from titles_test 
            group by emp_no
)

正确写法,使用select *得出的表就不再是原表,可以查询时删除原表

delete from titles_test
where id not IN
        (
            select * from (
                 select min(id) 
                 from titles_test
                 group by emp_no
            ) t
        )

SQL62 出现三次以上相同积分的情况

题目地址

select number
from grade
group by number
HAVING count(number) >= 3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_popo_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值