mysql数据库实验4

3. 查询xscj数据库xs表中学号为081218的学生的情况。

select 姓名,学号,总学分 from xs
   where 学号='081218';

4. 查询xs表中总学分小于45分的学生的情况。

 select 姓名,学号,出生日期,总学分 from xs
   where 总学分<45;

5. 查询xs表中备注为空的同学的情况。

select 姓名,学号,出生日期,总学分 
        from xs
        where 备注<=>null;

6. 查询xs表中专业为通信工程,性别为男的同学的情况。

select 姓名,学号,出生日期,总学分 
        from xs
        where 专业名='通信工程' and 性别=1;

7. 查询xscj数据库xs表中姓“李”的学生学号、姓名、专业名及性别。

select 学号,姓名,专业名,性别
            from xs
            where 姓名 like'李%';

8. 查询xscj数据库xs表中,学号倒数第三个数字为1的学生的学号、姓名。

select 学号,姓名  from xs
   where 学号 like'%1__';

9. 查询xs表中名字包含下画线的学生学号和姓名。

select 学号,姓名  from xs
   where 学号 like'%#_%'escape'#';

10. 查询姓王的同学的学号、姓名和专业名。

select 学号,姓名,专业名
   from xs
   where 姓名 regexp '^王';

11. 查询学号里包含6、7、9的学生学号和姓名。

select 学号,姓名
   from xs
   where 学号 regexp '[6,7,9]';

12. 查询学号以08开头,以08结尾的学生学号、姓名和专业名。

select 学号,姓名,专业名
   from xs
   where 学号 regexp '^08.*08$';

13. 查询xscj数据库xs表中不在1995年出生的学生情况。

select 学号,姓名,专业名,出生日期
   from xs
   where 出生日期 not between'1995-1-1'and'1995-12-31';

14. 使用两种方式查询xs表中专业名为“计算机”、“通信工程”或“无线电”的学生的情况。

1.select*
     from xs
     where 专业名 in ('计算机','通信工程','无线电');
2.select*
     from xs
     where 专业名 ='计算机' or 专业名 ='通信工程' or 专业名 ='无线电';

15. 查询xscj数据库中总学分尚不明确的学生情况。

select *
     from xs
     where 总学分 is null;

16. 查找在xscj数据库中选修了课程号为206的课程的学生的姓名、学号和专业名。

select 姓名,学号,专业名
from xs
where 学号 in
       (select 学号 from xs_kc where 课程号 ='206');

17. 查找未选修离散数学的学生的姓名、学号、专业名。

select 姓名,学号,专业名
from xs
where 学号 not in
       (select 学号 from xs_kc where 课程号 in (select 课程号 from kc where 课程名 ='离散数学'));

18. 查找选修了离散数学的学生学号。

select 学号
from xs_kc
where 课程号 =(select 课程号 from kc where 课程名 ='离散数学');

19. 查找xs表中比所有计算机系的学生年龄都大的学生学号、姓名、专业名、出生日期。

select 学号,姓名,专业名,出生日期
from xs
where 出生日期<all (select 出生日期 from xs where 专业名 ='计算机');

20. 查找xs_kc表中课程号206的成绩不低于课程号101的最低成绩的学生的学号。

select 学号
from xs_kc
where 课程号 ='206' and 成绩 >=any (select 成绩 from xs_kc where 课程号 ='101');

21. 查找选修206号课程的学生姓名。

select 姓名
from xs
where exists (select * from xs_kc where 学号 =xs.学号 and 课程号 ='206');

22. 查找选修了全部课程的同学的姓名。

select 姓名
from xs
where not exists (select * from kc where not exists(select * from xs_kc where 学号 =xs.学号 and 课程号 =kc.课程号));

23. 从xs表中查找总学分大于50分的男同学的姓名和学号。

select 姓名,学号
from (select 姓名,学号,性别,总学分 from xs where 总学分 >50)as student
where 性别='1';



24. 从xs表中查找所有女学生的姓名、学号,以及与081101号学生的年龄差距。


select 学号,姓名,year(出生日期)-year((select 出生日期 from xs where 学号='081101'))as 年龄差距
from xs
where 性别=0;

25. 查找与081101号学生性别相同、总学分相同的学生学号和姓名。


select 学号,姓名
from xs
where(性别,总学分)=(select 性别,总学分 from xs where 学号='081101');

26. 查询YGGL数据库,找出所有姓王的员工的部门号。

select departmentID
   from employees
   where name regexp '^王';


27. 查询YGGL数据库,找出所有其地址中含有“中山”的员工的号码及部门号。


select employeeid,departmentID  from employees
   where address like'%#中山%'escape'#';

28. 查询YGGL数据库,查找员工号码中倒数第二个数字为0的姓名、地址和学历。

select name,address,education  from employees
   where employeeid like'%0_';


29. 找出所有收入在2000~3000元的员工号码。


select employeeid
   from salary
   where income  between'2000'and'3000';

30. 找出所有在部门“1”和“2”工作的员工的号码。

select employeeid
     from employees
     where departmentID in ('1','2');


31. 查找在财务部工作的员工的情况。

select*
     from employees
    where departmentID in ('1');


32. 用子查询的方法查找所有收入在2500元以下的员工的情况。


select * 
from employees
where employeeID in (select employeeID from salary where inCome < 2500);

33. 查找研发部年龄不低于市场部所有员工年龄的员工的姓名。


select name 
from employees
where departmentID in (select departmentID from departments where departmentName ='研发部') and
birthday > all(select birthday from employees where departmentID in
(select departmentID from departments where departmentName ='市场部'));

  • 13
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值