Alias and related precautions sql statement to the column parameters

1, using double quotes

select  count(*) "总数" from table;

2, the use of single quotes

select count(*) '总数' from table;

3, directly add an alias, separated by a space

select count(*) zongshu from table;

4, using as keywords connected

select count(*) as zongshu from table;

5, using the connection number = (SQLServer use)

select count(*) =zongshu from table;

Precautions

When we use an expression as an output, we can not directly use the Where Condition column judge conditions. 

For example, the following SQL statement:
 
SELECT ID, (C1 + C2) AS s from T1   WHERE s> 100  
  the SQL Server error: " Column Name s is invalid " 

Use the following statement to

select t2.*
from (select id, (c1 + c2) as c from t1) t2
where c > 100
 
  --或者
 
select t2.*
from (select id, c = c1+c2 from t1) t2
where c > 100
The order of execution of the SELECT statement
  . 1 . From statement
  2 . WHERE sentence (the binding conditions)
  . 3 . Start with the statement
  . 4 . Connect by statement
  . 5 . WHERE statement
 . 6 . Group by statement
  . 7 . HAVING statement
  . 8 . Model statement
  . 9 . SELECT statement
  10 . union, minus, intersect and other set of calculus calculus
  11 . statement by the Order

 

Guess you like

Origin www.cnblogs.com/chxmtl/p/11804251.html