博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sql别名无效_SQL别名
阅读量:2535 次
发布时间:2019-05-11

本文共 3582 字,大约阅读时间需要 11 分钟。

sql别名无效

Sql Alias

Sql Alias

SQL别名

There are cases when the column name or the table name that is existing in the database is not so human readable. We can use SQL ALIAS feature to assign a new name to the table or columns in our query.
在某些情况下,数据库中存在的列名或表名不是很容易理解。 我们可以使用SQL ALIAS功能为查询中的表或列分配新名称。

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用法。

表名称SQL别名 (SQL Alias For Table Name)

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列。

列名称SQL别名 (SQL Alias For Column Name)

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/

你可能感兴趣的文章
JavaScript数组方法之reduce
查看>>
Linux常用命令之文件搜索命令
查看>>
thinkphp自定义权限管理之名称判断
查看>>
C++ ORM ODB 入门介绍(一)
查看>>
C#_02.14_基础五_.NET类
查看>>
Flask 学习资源
查看>>
Android SDK下载和更新失败的解决方法 分类: Android...
查看>>
MVC2 强类型的 HTML Helper
查看>>
开发 Windows 8 应用 - 0 - windows 8 开发资源
查看>>
生成二维码图片的工具类
查看>>
Surface Pro 4远程桌面分辨率问题
查看>>
【转】包管理器Bower详细讲解
查看>>
JS膏集02
查看>>
程序员三个境界
查看>>
从微信小程序开发者工具源码看实现原理(一)- - 小程序架构设计
查看>>
ASP.NET 上的 Async/Await 简介
查看>>
Effective C++学习笔记(1)
查看>>
element-ui 组件源码分析整理笔记目录
查看>>
GridEh排序
查看>>
[oc学习笔记]多态
查看>>