系统设计与数据库系统 作业一 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”到“聊数据”:NL2SQL如何用自然语言解锁数据库?
本文系统性地阐述了自然语言转SQL(NL2SQL) 技术如何让非技术背景的业务分析师实现数据自助查询,从而提升数据驱动决策的效率与准确性。
从“写SQL”到“聊数据”:NL2SQL如何用自然语言解锁数据库?
|
5天前
|
SQL 人工智能 Linux
SQL Server 2025 RC1 发布 - 从本地到云端的 AI 就绪企业数据库
SQL Server 2025 RC1 发布 - 从本地到云端的 AI 就绪企业数据库
75 5
SQL Server 2025 RC1 发布 - 从本地到云端的 AI 就绪企业数据库
|
4天前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
|
5天前
|
关系型数据库 分布式数据库 数据库
阿里云数据库收费价格:MySQL、PostgreSQL、SQL Server和MariaDB引擎费用整理
阿里云数据库提供多种类型,包括关系型与NoSQL,主流如PolarDB、RDS MySQL/PostgreSQL、Redis等。价格低至21元/月起,支持按需付费与优惠套餐,适用于各类应用场景。
|
4月前
|
SQL 存储 关系型数据库
第二篇:关系型数据库的核心概念与 SQL 基础
本篇内容深入浅出地讲解了关系型数据库的核心概念与SQL基础,适合有一定计算机基础的学习者。文章涵盖数据库的基本操作(CRUD)、数据类型、表的创建与管理等内容,并通过实例解析SELECT、INSERT、UPDATE、DELETE等语句的用法。此外,还推荐了多种学习资源与实践建议,帮助读者巩固知识。学完后,你将掌握基础数据库操作,为后续高级学习铺平道路。
235 1
|
22天前
|
SQL Oracle 关系型数据库
Oracle数据库创建表空间和索引的SQL语法示例
以上SQL语法提供了一种标准方式去组织Oracle数据库内部结构,并且通过合理使用可以显著改善查询速度及整体性能。需要注意,在实际应用过程当中应该根据具体业务需求、系统资源状况以及预期目标去合理规划并调整参数设置以达到最佳效果。
81 8
|
27天前
|
SQL 人工智能 Java
用 LangChain4j+Ollama 打造 Text-to-SQL AI Agent,数据库想问就问
本文介绍了如何利用AI技术简化SQL查询操作,让不懂技术的用户也能轻松从数据库中获取信息。通过本地部署PostgreSQL数据库和Ollama模型,结合Java代码,实现将自然语言问题自动转换为SQL查询,并将结果以易懂的方式呈现。整个流程简单直观,适合初学者动手实践,同时也展示了AI在数据查询中的潜力与局限。
183 8
|
1月前
|
SQL 人工智能 Linux
SQL Server 2025 RC0 发布 - 从本地到云端的 AI 就绪企业数据库
SQL Server 2025 RC0 发布 - 从本地到云端的 AI 就绪企业数据库
117 5
|
10天前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎,提供高性价比、稳定安全的云数据库服务,适用于多种行业与业务场景。
|
3月前
|
SQL 关系型数据库 MySQL
Go语言数据库编程:使用 `database/sql` 与 MySQL/PostgreSQL
Go语言通过`database/sql`标准库提供统一数据库操作接口,支持MySQL、PostgreSQL等多种数据库。本文介绍了驱动安装、连接数据库、基本增删改查操作、预处理语句、事务处理及错误管理等内容,涵盖实际开发中常用的技巧与注意事项,适合快速掌握Go语言数据库编程基础。
272 62