|
In the SQL Alias section, we saw that the syntax for using table and column aliases is as follows:
SELECT "table_alias"."column_name1" "column_alias"
FROM "table_name" "table_alias"
The keyword AS is used to assign an alias to the column or a table. It is insert between the column name and the column alias or between the table name and the table alias. The syntax for using AS is as follows:
SELECT "table_alias"."column_name1" AS "column_alias"
FROM "table_name" AS "table_alias"
Let's take a look at the same example as we used in SQL Alias. Assume we have the following table, Store_Information,
Table Store_Information
| store_name | Sales | Date |
| Los Angeles | $1500 | Jan-05-1999 |
| San Diego | $250 | Jan-07-1999 |
| Los Angeles | $300 | Jan-08-1999 |
| Boston | $700 | Jan-08-1999 |
To find total sales by store using AS as part of the table and column alias, we type in:
SELECT A1.store_name Store, SUM(A1.Sales) AS "Total Sales"
FROM Store_Information AS A1
GROUP BY A1.store_name
Result:
| Store | | Total Sales |
| Los Angeles | | $1800 |
| San Diego | | $250 |
| Boston | | $700 |
Next: SQL Join
|
| Copyright © 2013 1keydata.com All Rights Reserved.
Privacy Policy |
|