Linux SQL statement concise tutorial --- Alias, concise tutorial --- alias

Source: Internet
Author: User

Linux SQL statement concise tutorial --- Alias, concise tutorial --- alias

Next, we will discuss the use of alias in SQL. The most common aliases are column aliases and table aliases.

To put it simply, the column alias aims to make the SQL results readable. In the previous example, whenever we have a total turnover, the column name is SUM (Sales ). Although there is no problem in this case, if this column is not a simple sum, but a complicated calculation, then the column name is not so easy to understand. If we use a column alias, we can confirm that the column name in the result is easy to understand.

The Second alias is the table alias. To get an alias for a tableFROMThe table name in the clause is empty, and then the table alias to be used is listed. This is convenient when we use SQL to obtain data from several different tables. We will see this later when talking about join.

Let's take a look at the syntax of the column alias and table alias:

SELECT "table alias". "column 1" "column alias"
FROM "table name" "table alias ";

Basically, these two aliases are placed behind the objects to be replaced, and they are separated by a blank space. We continue to useStore_InformationThis table is used as an example:

Store_InformationTable

Store_Name Sales Txn_Date
Los Angeles 1500 05-Jan 1999
San Diego 250 07-Jan-1999
Los Angeles 300 08-Jan 1999
Boston 700 08-Jan 1999

We useSQL GROUPThe example on that page is the same. The difference here is that we have added the column alias and table alias:

SELECT A1.Store _ Name Store, SUM (A1.Sales) 'total sales'
FROM Store_Information A1
Group by A1.Store _ Name;

Result:

Store Total Sales
Los Angeles 1800
San Diego 250
Boston 700

In the results, the information itself is not different. The difference is the title of the column. This is the result of using the column alias. In the second column, our original title is "Sum (Sales)", but now we have a clear "Total Sales ". Obviously, "Total Sales" can more accurately describe the meaning of this field than "Sum (Sales. The benefits of using Table aliases are not shown here,Next page (SQL Join)It will be very clear.


Linux has been tested as follows:




Reprinted, please note: Xiao Liu

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.