系统设计与数据库系统 作业一 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.

相关文章
|
3月前
|
SQL 开发框架 .NET
ASP.NET连接SQL数据库:详细步骤与最佳实践指南ali01n.xinmi1009fan.com
随着Web开发技术的不断进步,ASP.NET已成为一种非常流行的Web应用程序开发框架。在ASP.NET项目中,我们经常需要与数据库进行交互,特别是SQL数据库。本文将详细介绍如何在ASP.NET项目中连接SQL数据库,并提供最佳实践指南以确保开发过程的稳定性和效率。一、准备工作在开始之前,请确保您
345 3
|
29天前
|
SQL Oracle 数据库
使用访问指导(SQL Access Advisor)优化数据库业务负载
本文介绍了Oracle的SQL访问指导(SQL Access Advisor)的应用场景及其使用方法。访问指导通过分析给定的工作负载,提供索引、物化视图和分区等方面的优化建议,帮助DBA提升数据库性能。具体步骤包括创建访问指导任务、创建工作负载、连接工作负载至访问指导、设置任务参数、运行访问指导、查看和应用优化建议。访问指导不仅针对单条SQL语句,还能综合考虑多条SQL语句的优化效果,为DBA提供全面的决策支持。
68 11
|
1月前
|
SQL 关系型数据库 MySQL
MySQL导入.sql文件后数据库乱码问题
本文分析了导入.sql文件后数据库备注出现乱码的原因,包括字符集不匹配、备注内容编码问题及MySQL版本或配置问题,并提供了详细的解决步骤,如检查和统一字符集设置、修改客户端连接方式、检查MySQL配置等,确保导入过程顺利。
|
1月前
|
SQL 监控 安全
SQL Servers审核提高数据库安全性
SQL Server审核是一种追踪和审查SQL Server上所有活动的机制,旨在检测潜在威胁和漏洞,监控服务器设置的更改。审核日志记录安全问题和数据泄露的详细信息,帮助管理员追踪数据库中的特定活动,确保数据安全和合规性。SQL Server审核分为服务器级和数据库级,涵盖登录、配置变更和数据操作等事件。审核工具如EventLog Analyzer提供实时监控和即时告警,帮助快速响应安全事件。
|
2月前
|
SQL 数据采集 监控
局域网监控电脑屏幕软件:PL/SQL 实现的数据库关联监控
在当今网络环境中,基于PL/SQL的局域网监控系统对于企业和机构的信息安全至关重要。该系统包括屏幕数据采集、数据处理与分析、数据库关联与存储三个核心模块,能够提供全面而准确的监控信息,帮助管理者有效监督局域网内的电脑使用情况。
41 2
|
2月前
|
SQL Java 数据库连接
canal-starter 监听解析 storeValue 不一样,同样的sql 一个在mybatis执行 一个在数据库操作,导致解析不出正确对象
canal-starter 监听解析 storeValue 不一样,同样的sql 一个在mybatis执行 一个在数据库操作,导致解析不出正确对象
|
3月前
|
SQL 关系型数据库 MySQL
Go语言项目高效对接SQL数据库:实践技巧与方法
在Go语言项目中,与SQL数据库进行对接是一项基础且重要的任务
114 11
|
3月前
|
SQL 监控 数据库
慢SQL对数据库写入性能的影响及优化技巧
在数据库管理系统中,慢SQL(即执行缓慢的SQL语句)不仅会影响查询性能,还可能对数据库的写入性能产生显著的不利影响
|
3月前
|
SQL 数据库 数据库管理
数据库SQL函数应用技巧与方法
在数据库管理中,SQL函数是处理和分析数据的强大工具
|
3月前
|
SQL 存储 数据可视化
SQL 数据库大揭秘:连接数字世界的魔法桥梁
在数字化时代,数据如繁星般璀璨,而 SQL 数据库则像强大的引力场,有序汇聚、整理和分析这些数据。SQL 数据库是一个巨大的数字宝库,装满各行各业的“宝藏”。本文将带你探索 SQL 数据库在电商、金融、医疗和教育等领域的应用。例如,在电商中,它能精准推荐商品;在金融中,它是安全卫士,防范欺诈;在医疗中,它是健康管家,管理病历;在教育中,则是智慧导师,个性化教学。此外,还将介绍如何利用板栗看板等工具实现数据可视化,提升决策效率。