系统设计与数据库系统 作业一 Basic SQL command LAB(下)

简介: 系统设计与数据库系统 作业一 Basic SQL command LAB(下)
  1. Find all employees whose job is either Clerk or Salesman.


SELECT * FROM emp2019284073 WHERE JOB = "CLERK" OR JOB = "SALESMAN"

625b0a98d2534f2f95e6955287194c7b.png



  1. Find any Clerk who is not in department 10


SELECT * FROM emp2019284073 WHERE DEPTNO!=10


c2ac5c0fef8242f59bdf53fce8550d89.png


Find everyone whose job is Salesman and all the Analysts in department 20


SELECT * FROM emp2019284073 WHERE JOB = 'SALESMAN' OR (JOB = 'ANALYST' AND DEPTNO = 20);

5daebef825a44f5db802b4734a9a9094.png


  1. Find all the employees who earn between £15,000 and £20,000. Show the employee name, department and salary.


SELECT ENAME,DEPTNO,SAL FROM emp2019284073 WHERE SAL BETWEEN 15000 AND 20000;


a38a2b7330ec481da1a0dd46fe2f32ab.png


  1. Find the name of the President.


SELECT ENAME FROM emp2019284073 WHERE JOB = 'PRESIDENT';


35d897303a734f2da23118e52e5198f0.png


  1. Find all the employees whose last names end with S


SELECT * FROM emp2019284073 WHERE ENAME LIKE '%S';


28d49b39bbbd40d2b14fb4d679ece982.png


  1. List the employees whose names have TH or LL in them


SELECT * FROM emp2019284073 WHERE ENAME LIKE '%TH%' OR ENAME LIKE '%LL%';


  1. List only those employees who receive commission.


SELECT * FROM emp2019284073 WHERE COMM IS NOT NULL;

9ae5279b61514335abb1d607477e2806.png



Find the name, job, salary, hiredate, and department number of all employees by alphabetical order of name.


SELECT ENAME,JOB,SAL,HIREDATE,DEPTNO FROM emp2019284073 ORDER BY ENAME;

fe08ff6d75af494e895781a9df1352ee.png


  1. Find the name, job, salary, hiredate and department number of all employees in ascending order by their salaries.
SELECT ENAME,JOB,SAL,HIREDATE,DEPTNO FROM emp2019284073 ORDER BY SAL DESC;


6d900d22293649019c6cea71f24de651.png


  1. List all salesmen in descending order by commission divided by their salary


SELECT * FROM emp2019284073 ORDER BY ifnull(COMM, 0)/SAL DESC;


  1. Order employees in department 30 who receive commision, in ascending order by commission
SELECT * FROM emp2019284073 WHERE DEPTNO=30 AND COMM IS NOT NULL ORDER BY COMM DESC;


Find the names, jobs, salaries and commissions of all employees who do not have managers.


SELECT ENAME,JOB,SAL,COMM FROM emp2019284073 WHERE MGR IS NULL;


Find all the salesmen in department 30 who have a salary greater than or equal to £18000.

SELECT * FROM emp2019284073 WHERE DEPTNO=30 AND JOB = 'SALESMAN' AND SAL >= 18000;



  1. Find the employees who were hired before 01-Jan-1998 and have salary above 5000 or below 1000.
SELECT * FROM emp2019284073 WHERE HIREDATE<'1998-01-01' AND (SAL > 5000 OR SAL<1000);


  1. What is the command to add primary key constraint to EMPNO


ALTER TABLE emp2019284073 ADD PRIMARY KEY(EMPNO);


  1. What is the command to add a new column EMP_family_name to existing EMP table


ALTER TABLE emp2019284073 ADD EMP_family_name VARCHAR(20);


  1. How to drop primary key constraint for EMPNO


ALTER TABLE emp2019284073 DROP PRIMARY KEY;


  1. rename EMP table to EMPLOYEE


RENAME TABLE emp2019284073 TO EMPLOYEE_2019284073;


  1. rename EMPLOYEE back to EMP


RENAME TABLE EMPLOYEE_2019284073 TO emp2019284073;


  1. What is the SQL command to remove column EMP_family_name from EMP table


ALTER TABLE emp2019284073 DROP COLUMN EMP_family_name;


  1. What is the SQL command to copy emp table to employee table


CREATE TABLE EMPLOYEE_2019284073 AS SELECT * FROM emp2019284073;


  1. What is the SQL command to drop employee table


DROP TABLE EMPLOYEE_2019284073;


  1. What is the SQL command to display name’s of employee entered interactively from user


SELECT * FROM emp2019284073 WHERE ENAME = '&ENTER';


  1. What is the SQL command to find the employee whose commission is NULL


SELECT * FROM emp2019284073 WHERE COMM IS NULL;



3. Experiment process and content


From this experiment of MySQL, I learned how to build a database, how to initialize the database, how to insert data into tables and how to select and edit values by language of MySQL.

MySQL has more convenient way to deal with huge data, which makes it fast to run. In addition, it offers enough operations to deal with this data.

During this experiment, errors occur sometimes. With the help of my classmates and knowledge in Internet, I finally finished this experiment successfully.

相关文章
|
1天前
|
SQL 数据库
数据库SQL语言实战(六)
本次实战的重点就在于对表格本身的一些处理,包括复制表格、修改表格结构、修改表格数据
|
1天前
|
SQL Oracle 关系型数据库
数据库SQL语言实战(五)(数据库系统概念第三章练习题)
本文的SQL语言适用的是Oracle数据库与mySQL可能存在略微不同
|
1天前
|
SQL Oracle 关系型数据库
数据库SQL语言实战(四)(数据库系统概念第三章练习题)
本文的SQL语言适用的是Oracle数据库与mySQL可能存在略微不同
数据库SQL语言实战(四)(数据库系统概念第三章练习题)
|
1天前
|
SQL Oracle 关系型数据库
数据库SQL语言实战(三)
本篇文章重点在于SQL中的各种删除操作
|
2天前
|
SQL 数据库
SQL主体内容一致,但是对于不同的数据库,对于SQL就可能有一些细节的拓展
SQL主体内容一致,但是对于不同的数据库,对于SQL就可能有一些细节的拓展
11 1
|
3天前
|
SQL 存储 数据库连接
C#SQL Server数据库基本操作(增、删、改、查)
C#SQL Server数据库基本操作(增、删、改、查)
7 0
|
3天前
|
SQL 存储 小程序
数据库数据恢复—Sql Server数据库文件丢失的数据恢复案例
数据库数据恢复环境: 5块硬盘组建一组RAID5阵列,划分LUN供windows系统服务器使用。windows系统服务器内运行了Sql Server数据库,存储空间在操作系统层面划分了三个逻辑分区。 数据库故障: 数据库文件丢失,主要涉及3个数据库,数千张表。数据库文件丢失原因未知,不能确定丢失的数据库文件的存放位置。数据库文件丢失后,服务器仍处于开机状态,所幸未写入大量数据。
数据库数据恢复—Sql Server数据库文件丢失的数据恢复案例
|
4天前
|
SQL 数据库
SQL数据库基础语法-查询语句
SQL数据库基础语法-查询语句
|
1天前
|
SQL 存储 数据库连接
LabVIEW与SQL Server 2919 Express通讯
LabVIEW与SQL Server 2919 Express通讯
|
2天前
|
SQL Windows
安装SQL Server 2005时出现对性能监视器计数器注册表值执行系统配置检查失败的解决办法...
安装SQL Server 2005时出现对性能监视器计数器注册表值执行系统配置检查失败的解决办法...
12 4