sql基础教程亚马逊

SQL is used in a wide variety of programming jobs. It's important to be familiar with SQL if you are going to be interviewing soon for a software position. This is especially true if you are going to interview at a top tech company such as Amazon, Apple, or Google.

SQL被广泛用于各种编程工作中。 如果您即将面试软件职位,那么熟悉SQL非常重要。 如果您要去亚马逊,苹果或谷歌这样的顶级科技公司面试,尤其如此。

This guide will cover basic SQL syntax as a refresher and then list some common SQL interview questions. The answers for all questions are given and you can use this information to study for your programming interview.

本指南将复习基本SQL语法,然后列出一些常见SQL面试问题。 给出了所有问题的答案,您可以使用此信息来学习编程面试。

基本SQL语法示例 (Basic SQL Syntax Example)

SQL is an international standard (ISO), but you will find some differences between implementations. This guide uses MySQL as an example because it's the most popular implementation of SQL.

SQL是国际标准(ISO),但是您会发现实现之间存在一些差异。 本指南以MySQL为例,因为它是最流行SQL实现。

如何使用特定的数据库 (How to use a specific database)

Here is the SQL command used to select the database containing the tables for your SQL statements:

这是用于选择包含SQL语句表的数据库SQL命令:

USE fcc_sql_guides_database;

SELECT和FROM子句 (SELECT and FROM clauses)

Use SELECT to determine which columns of the data you want to show in the results. There are also options you can use to show data that is not a table column.

使用SELECT确定要在结果中显示数据的哪些列。 还有一些选项可用于显示不是表列的数据。

The following example shows two columns selected from the “student” table, and two calculated columns. The first of the calculated columns is a meaningless number, and the other is the system date.

以下示例显示了从“学生”表中选择的两列,以及两个计算出的列。 计算的第一列是无意义的数字,另一个是系统日期。

SELECT studentID, FullName, 3+2 AS five, now() AS currentDate FROM student;

WHERE子句 (WHERE clause)

The WHERE clause specifies a condition while getting data. The WHERE clause is used to limit the number of rows returned. It's often used in a SELECT statement but can also be used in other statements such as UPDATE and DELETE.

WHERE子句指定获取数据时的条件。 WHERE子句用于限制返回的行数。 它通常用在SELECT语句中,但也可以用在其他语句中,例如UPDATE和DELETE。

Here is the basic syntax of the WHERE clause:

这是WHERE子句的基本语法:

SELECT column1, column2
FROM table_name
WHERE [condition]

The condition in a WHERE clause can include logical operators like >, <, =, LIKE, NOT, AND, OR.

WHERE子句中的条件可以包括>,<,=,LIKE,NOT,AND或OR之类的逻辑运算符。

Here is an example of a SQL statment using the WHERE clause. It specifies that if any of the students have certain SAT scores (1000, 1400), they will not be presented:

这是使用WHERE子句SQL语句的示例。 它指定如果任何学生的SAT分数达到一定(1000、1400),则不会显示以下内容:

SELECT studentID, FullName, sat_score, recordUpdated
FROM student
WHERE (studentID BETWEEN 1 AND 5OR studentID = 8OR FullName LIKE '%Maximo%')AND sat_score NOT IN (1000, 1400);

订单依据(ASC,DESC) (ORDER BY (ASC, DESC))

ORDER BY gives us a way to sort the result set by one or more of the items in the SELECT section.

ORDER BY提供了一种方法,可以按SELECT部分​​中的一个或多个项目对结果集进行排序。

Here is the same list as above, but sorted by the student's Full Name. The default sort order is ascending (ASC), but to sort in the opposite order (descending) you use DESC, as in the example below:

这是与上述相同的列表,但按学生的全名排序。 默认的排序顺序是升序(ASC),但是要使用相反的顺序(降序),请使用DESC,如下例所示:

SELECT studentID, FullName, sat_score
FROM student
WHERE (studentID BETWEEN 1 AND 5OR studentID = 8OR FullName LIKE '%Maximo%')AND sat_score NOT IN (1000, 1400)
ORDER BY FullName DESC;

分组并拥有 (GROUP BY and HAVING)

GROUP BY gives us a way to combine rows and aggregate data. The HAVING clause is like the above WHERE clause, except that it acts on the grouped data.

GROUP BY为我们提供了一种合并行和汇总数据的方法。 HAVING子句类似于上面的WHERE子句,不同之处在于它作用于分组的数据。

The SQL statement below answers the question: “Which candidates received the largest number of contributions (ordered by count (*)) in 2016, but only those who had more than 80 contributions?”

下面SQL语句回答了以下问题:“ 2016年,哪些候选人获得的捐款数量最多(按计数(*)排序),但只有那些捐款超过80的候选人?”

Ordering this data set in a descending (DESC) order places the candidates with the largest number of contributions at the top of the list.

按降序(DESC)排序此数据集,将贡献最大的候选者放在列表的顶部。

SELECT Candidate, Election_year, SUM(Total_$), COUNT(*)
FROM combined_party_data
WHERE Election_year = 2016
GROUP BY Candidate, Election_year
HAVING count(*) > 80
ORDER BY count(*) DESC;

常见SQL面试问题 (Common SQL Interview Questions)

什么是SQL中的内部联接? (What is an inner join in SQL?)

This is the default type of join if no join is specified. It returns all rows in which there is at least one match in both tables.

如果未指定连接,则这是默认的连接类型。 它返回两个表中至少有一个匹配项的所有行。

SELECT * FROM A x JOIN B y ON y.aId = x.Id

什么是SQL中的左联接? (What is a left join in SQL?)

A left join returns all rows from the left table, and the matched rows from the right table. Rows in the left table will be returned even if there was no match in the right table. The rows from the left table with no match in the right table will have null for right table values.

左联接返回左表中的所有行,并返回右表中的匹配行。 即使右表中没有匹配项,也将返回左表中的行。 左表中没有匹配项的行在右表中将为null对于右表值。

SELECT * FROM A x LEFT JOIN B y ON y.aId = x.Id

什么是SQL中的正确联接? (What is a right join in SQL?)

A right join returns all rows from the right table, and the matched rows from the left table. Opposite of a left join, this will return all rows from the right table even where there is no match in the left table. Rows in the right table that have no match in the left table will have null values for left table columns.

右联接返回右表中的所有行,以及左表中的匹配行。 与左联接相反,这将返回右表中的所有行,即使左表中没有匹配项也是如此。 右表中与左表不匹配的行的左表列将具有null值。

SELECT * FROM A x RIGHT JOIN B y ON y.aId = x.Id

什么是SQL中的完全联接或完全外部联接? (What is a full join or full outer join in SQL?)

A full outer join and a full join are the same thing. The full outer join or full join returns all rows from both tables, matching up the rows wherever a match can be made and placing NULLs in the places where no matching row exists.

完全外部联接和完全联接是同一回事。 完全外部联接或完全联接返回两个表中的所有行,在可以进行匹配的地方匹配这些行,并将NULL放置在不存在匹配行的位置。

SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName

以下命令的结果是什么? (What is the result of the following command?)

DROP VIEW view_name

This will result in an error because you can’t perform a DML operation on a view. A DML operation is any operation that manipulates the data such as DROP, INSERT, UPDATE, and DELETE.

这将导致错误,因为您无法在视图上执行DML操作。 DML操作是任何操作数据的操作,例如DROP,INSERT,UPDATE和DELETE。

使用ALTER命令后可以执行回滚吗? (Can we perform a rollback after using ALTER command?)

No, because ALTER is a DDL command and Oracle server performs an automatic COMMIT when the DDL statements are executed. DDL statements define data structures such as CREATE table and ALTER table.

不可以,因为ALTER是DDL命令,并且在执行DDL语句时Oracle服务器执行自动COMMIT。 DDL语句定义数据结构,例如CREATE tableALTER table

在列级别执行规则的唯一约束是什么? (Which is the only constraint that enforces rules at column level?)

NOT NULL is the only constraint that works at the column level.

NOT NULL是在列级别上起作用的唯一约束。

SQL中的伪列是什么? 举一些例子? (What are the pseudocolumns in SQL? Give some examples?)

A pseudocolumn behaves like a column, but is not actually stored in the table because it is all generated values. The values of a pseudocolumn can be selected but they cannot be inserted, updated, or deleted.

伪列的行为类似于列,但实际上并没有存储在表中,因为它都是生成的值。 可以选择伪列的值,但是不能插入,更新或删除它们。

ROWNUM, ROWID, USER, CURRVAL, NEXTVAL etc.

创建一个密码为“ kmd26pt”的用户“ my723acct”。 使用PO8提供的“ user_data”和临时数据表空间,并向该用户提供“ user_data”中10M的存储空间和“ temporary_data”中5M的存储空间。 (Create a user "my723acct" with password "kmd26pt". Use the "user_data" and temporary data tablespaces provided by PO8 and provide to this user 10M of storage space in "user_data" and 5M of storage space in "temporary_data".)

CREATE USER my723acct IDENTIFIED BY kmd26pt
DEFAULT TABLESPACE user_data
TEMPORARY TABLESPACE temporary_data
QUOTA 10M on user_data QUOTA 5M on temporary_data

创建角色 role_tables_and_views (Create the role role_tables_and_views.)

CREATE ROLE role_tables_and_views

向上一个问题的角色授予连接数据库的特权以及创建表和视图的特权。 (Grant to the role of the previous question the privileges to connect to the database and the privileges to create tables and views.)

The privilege to connect to the database is CREATE SESSION The privilege to create table is CREATE TABLE The privilege to create view is CREATE VIEW

连接数据库的特权是CREATE SESSION创建表的特权是CREATE TABLE创建视图的特权是CREATE VIEW

GRANT CREATE SESSION, CREATE TABLE, CREATE VIEW TO role_tables_and_views

将问题的先前角色授予用户annyrita (Grant the previous role in the question to the users anny and rita.)

GRANT role_tables_and_views TO anny, rita

编写命令以将用户rita的密码从“ abcd”更改为“ dfgh” (Write a command to change the password of the user rita from "abcd" to "dfgh")

ALTER USER rita IDENTIFIED BY dfgh

用户ritaannyscott创建的INVENTORY表上没有SELECT特权。 编写命令以允许scott向用户授予这些表的SELECT特权。 (The users rita and anny do not have SELECT privileges on the table INVENTORY that was created by scott. Write a command to allow scott to grant the users SELECT privileges on theses  tables.)

GRANT select ON inventory TO rita, anny

用户 rita 已转移,不再需要通过角色授予她的特权 role_tables_and_views 。 编写命令以将其从先前授予的特权中删除。 她仍然应该能够连接到数据库。 (User rita has been transferred and no longer needs the privilege that was granted to her through the role role_tables_and_views. Write a command to remove her from her previously given privileges. She should still be able to connect to the database.)

REVOKE select ON scott.inventory FROM rita
REVOKE create table, create view FROM rita

已转移的用户rita现在移至另一家公司。 由于她创建的对象不再使用,因此编写命令以删除该用户及其所有对象。 (The user rita who was transferred is now moving to another company. Since the objects she created are no longer used, write a command to remove this user and all her objects.)

The CASCADE option is necessary to remove all the objects of the user in the database.

CASCADE选项对于删除数据库中用户的所有对象是必需的。

DROP USER rita CASCADE

编写SQL查询以从“雇员”表中找到第n个最高的“工资”。 (Write an SQL query to find the nth highest "Salary" from the "Employee" table.)

SELECT TOP 1 SalaryFROM (SELECT DISTINCT TOP N SalaryFROM EmployeeORDER BY Salary DESC)ORDER BY Salary ASC

结论 (Conclusion)

If you think you can answer all these questions, you may be ready for your interview. Good luck!

如果您认为自己可以回答所有这些问题,则可能已准备好接受面试。 祝好运!

翻译自: https://www.freecodecamp.org/news/common-sql-interview-questions/

sql基础教程亚马逊

sql基础教程亚马逊_针对Amazon,Apple,Google的常见SQL面试问题相关推荐

  1. 亚马逊广告接口 amazon advert api 申请流程

    #亚马逊广告接口 amazon advert api 申请流程 官方文档 https://advertising.amazon.com/API/docs/en-us 申请连接 : https://ad ...

  2. 亚马逊公司(Amazon)

    亚马逊公司(Amazon)是互联网最大的在线零售商,也是世界上最早以商业化运营模式为用户提供远程云计算平台服务的公司.亚马逊公司的弹性云计算平台(EC2)相对于Google.IBM和微软云计算平台而言 ...

  3. 亚马逊国际获得AMAZON商品详情API,数据接口

    万邦亚马逊国际获得AMAZON商品详情 API 返回值说明 item_get-获得AMAZON商品详情 onebound.amazon.item_get 公共参数 请求地址: 跨境电商平台接口提供商 ...

  4. 亚马逊云科技Amazon S3存储与客户的“独家记忆”

    2023年3月14日是亚马逊云科技Amazon S3的17周岁生日,与这些宏大的.不可量化的概念与母题相比,Amazon S3更像是一位可靠的朋友.作为亚马逊云科技的众多服务中最热门的对象存储服务,1 ...

  5. 亚马逊云科技Amazon DeepRacer互联网行业全国冠军诞生

    1月11日,首届亚马逊云科技Amazon DeepRacer自动驾驶赛车互联网行业全国总决赛圆满结束,从全国各地选拔出的9支冠军队伍齐聚滨海三亚,向总决赛的桂冠发起了冲击. 本次比赛沿袭了Amazon ...

  6. 新睿云 亚马逊_等待亚马逊新的可穿戴需求,让我穿着内衣

    新睿云 亚马逊 Amazon says your semi-nude pictures will be automatically deleted from its servers after 3D ...

  7. router 53 亚马逊_亚马逊53号公路

    router 53 亚马逊 Amazon Route 53 is a DNS (Domain Name System) web service on AWS Cloud. As we all know ...

  8. 四巨头 亚马逊_科技巨头亚马逊能否在拥挤的mmo空间中竞争

    四巨头 亚马逊 Everyone knew that Amazon entering the game dev industry was going to be a fascinating story ...

  9. Ubuntu MySQL 亚马逊_亚马逊EC2 ubuntu下安装mysql远程无法连接问题o

    无法远程的原因有很多,我今天遇到的问题是通过navicat无法远程连接我在EC2上创建的实例. 1.通过命令" netstat -an|grep 3306 "检查一下3306端口对 ...

最新文章

  1. c语言神州行用户,神州行焕新出发 你行我行神州行折射品牌自信心
  2. GIS+=地理信息+云计算技术——Spark集群部署
  3. 计算机组成原理中12H是什么,计算机组成原理课程实习报告.doc
  4. 安全36计 你需要了解的那些安全术语
  5. Sicily 6768. Log Books 解题报告
  6. 【转】SAP整合技术研究
  7. 问题 | 解决Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll 问题(pycharm+Tensorflow)
  8. 复现经典:《统计学习方法》第 12 章 监督学习方法总结
  9. NOIP提高组复赛 知识点整理
  10. 阿里云轻应用服务器 宝塔面板 mongodb 配置外网连接 其一 基础配置
  11. MyBatis的逆向工程工具,自动生成数据库对应的POJO实体类、mapper接口、增删改查mapper.xml文件
  12. 一个广为流传的关于项目管理的通俗讲解
  13. mysql时间正确时区错误_在app中的日期时间但在mysql [时区]错误
  14. 农信社计算机知识,农信社备考:计算机基础知识(15)
  15. Math Type World2016安装
  16. TCP 实战抓包分析
  17. Android 开发,你遇上 Emoji 头疼吗?
  18. docker 僵尸进程
  19. 八叉网的神奇明链外链技术
  20. 什么是铠装光纤跳线及它的特点?

热门文章

  1. 【Leetcode | 6】136. 只出现一次的数字
  2. makefile的两个变量(自动变量和普通变量)
  3. Java高级面试题!java编程思想怎么学
  4. Spring主要用到两种设计模式
  5. hdfs的特性、命令、安全模式、基准测试
  6. HttpStatusCode
  7. 红外感应模块+蜂鸣器实现简易报警(转)
  8. python(1) - 数据类型和变量
  9. 软件公司管理基本原则
  10. [BFS]JZOJ 4672 Graph Coloring