本文共 3582 字,大约阅读时间需要 11 分钟。
sql别名无效
SQL ALIAS is used for temporary naming of table or column of a table for making it more readable. The renaming is temporary in nature and does not affect the real name of the table or the column of the table.
SQL ALIAS用于临时命名表或表的列,以使其更具可读性。 重命名本质上是临时的,不会影响表或表的列的真实名称。
The lifetime of the SQL ALIAS is till the duration of the query where SQL ALIAS is defined.
SQL ALIAS的生存期一直到定义SQL ALIAS的查询持续时间为止。
SQL ALIAS is more useful where multiple tables are involved like in case of JOINS.
SQL ALIAS在涉及多个表(如JOINS的情况)时更有用。
We will discuss the usage of SQL ALIAS for table and column name of the table in detail in the below-mentioned sections.
我们将在以下各节中详细讨论表的表名和列名SQL ALIAS用法。
Syntax:
语法 :
SELECT column_name(s) FROM table_name AS alias_name;
In the syntax above the alias_name is the name that will be temporarily assigned for the table_name.
在上面的语法中,alias_name是将临时分配给table_name的名称。
Let’s try an understand in detail about aliasing a table name using the below-mentioned example.
让我们尝试使用下面提到的示例来详细了解有关别名表名称的信息。
We will consider the below mentioned Product and Supplier table for example purpose.
我们将以下面提到的“产品和供应商”表为例。
Product Table:
产品表:
ProductID | ProductName | SupplierID |
---|---|---|
1 | Cookies | 2 |
2 | Jam | 2 |
3 | Butter | 1 |
4 | Bread | 3 |
5 | Cake | 1 |
产品编号 | 产品名称 | 供应商编号 |
---|---|---|
1个 | 饼干 | 2 |
2 | 果酱 | 2 |
3 | 牛油 | 1个 |
4 | 面包 | 3 |
5 | 蛋糕 | 1个 |
Supplier Table:
供应商表:
SupplierID | SupplierName |
---|---|
1 | ABC Company |
2 | ACD Industries |
3 | XYZ Pvt Ltd |
供应商编号 | 供应商名称 |
---|---|
1个 | 美国广播公司 公司 |
2 | ACD产业 |
3 | XYZ列印 有限公司 |
Scenario: Get the name of all the products and their supplier name along with the productid.
场景 :获取所有产品的名称及其供应商名称以及productid。
Query:
查询:
SELECT p.ProductID, p.ProductName, s.SupplierName FROM Product AS p, Supplier AS s WHERE p.SupplierID = s.SupplierID;
ProductID | ProductName | SupplierName |
---|---|---|
1 | Cookies | ACD Industries |
2 | Jam | ACD Industries |
3 | Butter | ABC Company |
4 | Bread | XYZ Pvt Ltd |
5 | Cake | ABC Company |
产品编号 | 产品名称 | 供应商名称 |
---|---|---|
1个 | 饼干 | ACD 产业领域 |
2 | 果酱 | ACD产业 |
3 | 牛油 | ABC公司 |
4 | 面包 | XYZ Pvt Ltd |
5 | 蛋糕 | ABC公司 |
In the output above SQL ALIAS, is used for aliasing the table name, making it easy to differentiate the two SupplierID columns of Product and Supplier table.
在SQL ALIAS上方的输出中,使用别名表名称,可以轻松区分Product和Supplier表的两个SupplierID列。
Syntax:
句法:
SELECT column_name AS alias_name FROM table_name;
In the syntax above the alias_name is the name that will be temporarily assigned for the column_name.
在上面的语法中,alias_name是将为column_name临时分配的名称。
Let’s try an understand in detail about aliasing a column name using the below-mentioned example.
让我们尝试使用下面提到的示例来详细了解有关别名别名的信息。
Scenario: Get the name of all the products and their supplier name along with the productid. The ProductName column should be displayed as Product and SupplierName column should be displayed as Supplier.
场景 :获取所有产品的名称及其供应商名称以及productid。 ProductName列应显示为Product,而SupplierName列应显示为Supplier。
Query:
查询:
SELECT p.ProductID, p.ProductName AS Product, s.SupplierName AS Supplier FROM Product AS p, Supplier AS s WHERE p.SupplierID = s.SupplierID;
ProductID | Product | Supplier |
---|---|---|
1 | Cookies | ACD Industries |
2 | Jam | ACD Industries |
3 | Butter | ABC Company |
4 | Bread | XYZ Pvt Ltd |
5 | Cake | ABC Company |
产品编号 | 产品 | 供应商 |
---|---|---|
1个 | 饼干 | ACD产业 |
2 | 果酱 | ACD产业 |
3 | 牛油 | ABC公司 |
4 | 面包 | XYZ Pvt Ltd |
5 | 蛋糕 | ABC公司 |
In the example above we have seen the usage of alias for table and column both in a single query.
在上面的示例中,我们已经在单个查询中看到了表和列别名的用法。
翻译自:
sql别名无效
转载地址:http://nmmzd.baihongyu.com/