1. query all information of employees whose second letter is t or
Copy codeThe Code is as follows:
Select *
From employees
Where firstname like '_ [t, a] %'
Note: In SQL, % indicates a string, so it cannot be annotated like matlab. The two double slashes do not seem to work either./**/Yes. Some netizens say that the single SQL line comment is --
2. Change the field name
Copy codeThe Code is as follows:
Select 'name' = firstname, 'surname' = lastname
From employees
Where firstname like '_ [t, a] %'
Or
Copy codeThe Code is as follows:
Select firstname as 'name', lastname as 'surname'
From employees
Where firstname like '_ [t, a] %'
Iii. top keywords
Copy codeThe Code is as follows:
/* Retrieve the first 70% matching records */
Select top 70 percent firstname as 'name', lastname as 'surname'
From employees
Where firstname like '_ [t, a] %' 1/* retrieve the first two matching records */
Select top 2 firstname as 'name', lastname as 'surname'
From employees
Where firstname like '_ [t, a] %'
Iv. union keywords
Note: standard SQL only supports concurrent operations, but does not support intersection and minus operations.
Copy codeThe Code is as follows:
Select *
From employees
Where title = 'sales manager'
Union
Select *
From employees
Where address is not null
Display:
Server: Message 8163, level 16, status 4, Row 1
The text, ntext, or image data type cannot be selected in DISTINCT mode.
Copy codeThe Code is as follows:
Select *
From employees
Where title = 'sales manager'
Union all
Select *
From employees
Where address is not null
The analysis query in the query and analysis is to check whether there is a syntax error (ctrl + F5) and execute the query (right triangle) (F5) yes. If a syntax error occurs, the result is not executed.
5. compute keywords
The compute clause requires the following information:
The optional By keyword can be used to calculate the specified row aggregation for a column.
Row aggregation functions: sum, avg, min, max, count
Columns for which row Aggregate functions are to be executed
When compute has an optional By clause, each group that meets the select condition has two result sets:
The first result set of each group is a detailed row set, which contains the selection list information of the group.
The second result set of each group has a row, which contains the Note of the aggregate function specified in the COMPUTE clause of this group.
Copy codeThe Code is as follows:
Select sex, sclass, score
From student
Order by sex
Compute sum (score) by sex
Note: order by is required, and the parameters after compute by should appear in the parameters after order
Copy codeThe Code is as follows:
Select sex, sclass, score
From student
Compute sum (score)