In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The SQL statement can specify an alias for a table name or column name. Aliases are sometimes called export columns, and whether they are export columns or aliases, they all represent the same thing. )
SQL alias
SQL aliases are used to provide temporary names for a table or a column in a table.
SQL aliases are commonly used to make table or column names more readable.
An alias for SQL exists only during the query.
Aliases are given using the AS keyword.
Aliases are recommended in the following situations
The query involves multiple tables
Used to query functions
Two or more columns need to be put together
Long list or poor readability
Grammar
1. Alias syntax for table names:
SELECT column name FROM table name AS alias
2. Alias syntax for column names
SELECT column name AS alias FROM table name
3. Mixed syntax for aliases of table and column names
SELECT column name AS alias FROM table name AS alias
Grammar examples
1. Use the table name to alias
There are two tables: "Persons" and "Product_Orders". Assign them aliases "p" and "po", respectively. List all orders for "John Adams".
SELECT po.OrderID, p.LastName, p.FirstNameFROM Persons AS p, Product_Orders AS poWHERE p.LastNameplates Adams' AND p.FirstNameplates John'
2. Use column name aliases
Query the LastName column in the Persons table (define the alias' last name 'for it) and the FirstName column (define the alias' first name 'for it), and output all the result values.
SELECT LastName AS last name, FirstName AS first name FROM Persons
3. Use both table and column names
Define the alias' alias' for the city table and use that table alias to query all information about the ID column in the table (alias B is defined for the ID column).
SELECT A.ID AS BFROM city AS A
Here are some additions from others
1 Overview
This article briefly analyzes the basic usage of AS in SQL SERVER.
2 concrete analysis
2.1 define variable types
DECLARE @ UserName AS VARCHAR (50) = 'Alan_beijing'
2.2 aliases
2.2.1 alias the result set column
Code:
SELECT OrderID,CustID,OrderDate
FROM Orders
Result:
Code:
SELECT OrderID AS 'order ID',CustID AS' customer ID',OrderDate AS 'order date'
FROM Orders
Result:
2.2.2 alias the table
SELECT O.OrderID,O.CustID,O.OrderDate
FROM Orders AS O
2.2.3 alias for subquery
SELECT ChildQuery_Orders.OrderDate
FROM
(SELECT *
FROM Orders
WHERE CustID > = 5) AS ChildQuery_Orders
2.3 conversion types
2.3.1 CAST type conversion
SELECT CAST ('110' AS INT)-
2.3.2 CONVERT type conversion
SELECT CONVERT (decimal, '123.6')-123
2.4 create a view that represents the source of the base table
CREATE VIEW ViewDemo
AS
SELECT * FROM Orders
2.5 others (follow-up additions)
3 references
[01] Microsoft SqlServer 2008 Technical Insider: T-SQL language Foundation
[02] Microsoft SqlServer 2008 technical insider: T-SQL query
4 copyright
The supplementary content is provided by Alan_beijing.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.