I. Querying the entire information of an employee with a second letter of T or a
Copy Code code as follows:
SELECT *
From Employees
where FirstName like ' _[t,a]% '
Note: In SQL,% of the string, so do not like MATLAB with its comments, two double slash seems not,/**/can, have netizens say SQL single note as-
Two. Change field name
Copy Code code as follows:
Select ' Name ' = FirstName, ' surname ' = LastName
From Employees
where FirstName like ' _[t,a]% '
Or
Copy Code code as follows:
Select FirstName as ' name ', LastName as ' surname '
From Employees
where FirstName like ' _[t,a]% '
three. Top keyword
Copy Code code as follows:
* * Retrieve the first 70% records of the qualifying * *
Select top percent FirstName as ' name ', LastName as ' surname '
From Employees
where FirstName like ' _[t,a]% ' 1 * Retrieves the first 2 records that meet the criteria * *
Select top 2 firstname as ' name ', LastName as ' surname '
From Employees
where FirstName like ' _[t,a]% '
four. Union keyword
NOTE: Standard SQL provides and operates only and does not provide a intersection (minus) operation.
Copy Code code as follows:
SELECT *
From Employees
where title = ' Sales Manager '
Union
SELECT *
From Employees
Where address isn't null
Show:
Server: Message 8163, Level 16, State 4, line 1
You cannot select text, ntext, or image data types in DISTINCT mode.
Copy Code code as follows:
SELECT *
From Employees
where title = ' Sales Manager '
UNION ALL
SELECT *
From Employees
Where address isn't null
Query analysis in which the analysis query (check mark) is to see if there is a syntax error (CTRL + F5), the execution of the query (right triangle) (F5) is the result of the display if there is a syntax error does not execute.
Five. Compute keyword
The COMPUTE clause requires the following information:
Optionally by keyword to calculate the specified row aggregation on a column
Row aggregate functions: Sum,avg,min,max,count
column on which to perform row aggregate functions
When compute with an optional by clause, each group that meets the select criteria has two result sets:
The first result set for each group is the detail rowset, which contains the selection list information for the group
There is one row for the second result set for each group, which contains the subtotal of the aggregate function specified in the COMPUTE clause of the group
Copy Code code as follows:
Select Sex,sclass,score
From student
ORDER BY sex
Compute SUM (score) by sex
Note: The order by is mandatory, and the compute by parameter should appear in the argument after the
Copy Code code as follows:
Select Sex,sclass,score
From student
Compute SUM (Score)