Linux SQL statement Concise tutorial---Alias

Source: Internet
Author: User

Next, we discuss the use of the alias (alias) on SQL. There are two types of aliases that are most commonly used: field aliases and table aliases.

Simply put, the purpose of the field alias is to make the results of SQL generated easy to read. In the previous example, the field name is SUM (sales) whenever we have a total turnover. Although there is no problem in this case, if the field is not a simple summation, but a complex calculation, then the column name is not so easy to understand. If we use field aliases, we can confirm that the field names in the results are easy to understand.

The second type of alias is the table alias. To give a table an alias, simply empty a grid after the table name in the FROM clause, and then list the table aliases you want to use. This is handy when we want to use SQL to get data from several different tables. This is what we'll see later when we talk about join.

Let's take a look at the syntax for field aliases and table aliases:

Select "Table alias". " Field 1 "Field alias"
From "Table name" "Table alias";

Basically, both of these aliases are placed behind the objects they are replacing, and they are separated by a blank space. We continue to use the store_information form to do an example:

store_information Form

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 use the same example as the SQL GROUP by page. The difference here is that we've added field aliases and table aliases:

SELECT A1. Store_name Store, SUM (A1. Sales) ' Total sales '
From Store_information A1
GROUP by A1. Store_name;

Results:

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 field. This is the result of applying a field alias. In the second field, we originally had the title "Sum", and now we have a very clear "total sales". It is clear that total sales can describe the meaning of this field more precisely than Sum (sales). The benefits of using a table alias are not shown here, but this will be clear on the next page (SQL Join) .


Linux is measured as follows:




Reprint please specify: Xiao Liu

Linux SQL statement Concise tutorial---Alias

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.