数据库第二次作业

这篇博客主要涵盖了MySQL数据库的查询操作,包括选择特定字段、按条件过滤记录、范围查询、聚合函数应用、排序和连接查询等。通过一系列实例,如查询特定部门员工、工资范围、部门信息及员工统计,深入探讨了SQL查询的多种技巧和方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

查询语句

select e_no,e_name,e_salary from employee;
select *from employee where dept_no = 10 or  dept_no = 20;
select * ,(select d_name from dept d where d.d_no = e.dept_no ) 部门 from employee e where e_salary>800 and e_salary<2500;
select * ,(select d_name from dept d where d.d_no = e.dept_no ) 部门 from employee e where dept_no=20;
select * ,(select d_name from dept d where d.d_no = e.dept_no ) 部门 from employee e where e_salary=any(select max(e_salary) from employee e  group by e.dept_no);
select d_name ,d_location ,(SELECT e_name from employee where e_name= 'BLAKE') 姓名 from dept d where d.d_no=(select dept_no from employee where e_name = 'BLAKE');
select e.e_name,d.d_name,d.d_location from employee e,dept d where e.dept_no = d.d_no;
select count(1) ,d.d_name from employee e ,dept d  where e.dept_no = d.d_no group by  e.dept_no;
select sum(e_salary),d.d_name from employee e ,dept d  where e.dept_no = d.d_no group by  e.dept_no;
select avg(e_salary),d.d_name from employee e ,dept d  where e.dept_no = d.d_no group by  e.dept_no;
select *from employee where e_salary<1500;
select *from employee order by  e_no desc;
select *from emplyee where e_name regexp '^S'OR e_name regexp'^A';
/*14、不会
15、不会*/
select * from (select * ,row_number() over (order by e_salary) rownum from employee) g where g.rownum between 3 and 6;
select min(g.e_salary) from(select e_salary from employee where e_job = 'SALESMAN') g;
select e_name from employee  where e_name regexp 'N$' OR  e_name regexp 'S$';
select e_name,e_job from employee e where e.dept_no = (select d_no from dept where d_location='BeiJing');
/*20、不会*/
select * from employee   where hireDate > 2004-12-31 and  hireDate < 20016-01-01 and dept_no=20   union all select * from employee   where hireDate > 2004-12-31 and  hireDate < 20016-01-01 and dept_no=30 ;
select * from employee where e_name like '%A%'
select e_name from employee where e_name regexp '^.*T*C*M*.*$' ;

 

创建表以及表内容1111

create table employee(
		e_no  int(11) primary key not null unique,
		e_name  varchar(50)  not null,
		e_gender char(2),
		dept_no  int(11) not null,
		e_job  varchar(50)  not null,
		e_salary int(11) not null,
		hireDate date  not null
	);
create table dept(
		d_no int(11)  primary key auto_increment not null  unique,
		d_name varchar(50) not null,
		d_location  varchar(50)
);
	alter table employee add constraint pk_emp foreign key(dept_no) references dept(d_no);
		

1. 查询所有记录的e_no、e_name和e_salary字段值

2、 查询dept_no等于10和20的所有记录

 3. 查询工资范围在800~2500之间的员工信息

4. 查询部门编号为20的部门中的员工信息

5. 查询每个部门最高工资的员工信息 

6. 查询员工BLAKE所在部门和部门所在地

 

7、查询所有员工的部门和部门信息

8. 计算每个部门各有多少名员工

 9. 计算不同类型职工的总工资数

 

10. 计算不同部门的平均工资

 

 11、查询工资低于1500的员工信息

12. 将查询记录先按部门编号由高到低排列,再按员工工资由高到低排列 

 13、查询员工姓名以字母‘A’或‘S’开头的员工的信息

14、查询到目前为止工龄大于等于18年的员工信息

不会

15 、计算所有女员工(‘F’)的年龄

不会

16、使用LIMIT查询从第3条记录开始到第6条记录的结果

17. 查询销售人员(SALSEMAN)的最低工资

 

18. 查询名字以字母N或者S结尾的记录

19、查询在BeiJing工作的员工的姓名和职务

20、 使用左连接方式查询employee和dept表

不会

21、查询所有2001~2005年入职的员工的信息,查询部门编号为20和30的员工信息并使用UNION合并 两个查询结果

 22、使用LIKE查询员工姓名中包含字母a的记录

23、使用REGEXP查询员工姓名中包含T、C或者M这3个字母中任意1个的记录

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值