DQL
Basic Query
- field (column) control
1) Query all columns: SELECT * from table name ; "*" means querying all columns
2) Query the specified column: Select column 1, column 2, column N from table name ;
3) complete duplicate records only once
SELECT DISTINCT column name from table name ;
When the multiline record in the query results is identical, only one row is displayed.
This is rarely the case when querying all columns, but this is a big possibility when querying only one column.
4) column Operations
- Column of quantity type can do subtraction operation
- String type can do connection operation: 1, concat (' A ', ' B ') 2, Mysql cannot use ' + ' connection string
3. Convert null values
A) ifnull ( column value , conversion value)
b) Sometimes the column has a null value, the result of the operation or null, you want to operate as a different value
4. Alias list
A) after the column is calculated, the column name in the result set is not good-looking, you need to give the column name an alias
b) using as aliases, as can be omitted
2. Condition control
(1) conditional query: The Select statement can also use the where clause to control the record
(2) fuzzy query
① ' _ ' denotes any one character, and an underscore represents one character
② '% ' represents 0 to more characters
③ fuzzy lookups need to use the operator:like
3. Sorting
- Ascending ASC
- Descending desc
- sort by using the keyword ORDER by
(1) syntax:ORDER BY condition one , condition two , condition n asc/desc
Aggregation functions
- An aggregate function does a vertical operation on a column, and a null item does not participate in the Operation
- COUNT (*) number of calculations
- Max () Max value
- Min () min value
- SUM () and
- AVG () average
Group queries
- A group query is the grouping of records using a column, and then querying group information
- Group query is a set of information, not with personal information
- Group information
(1) grouping columns
(2) aggregation function
- grouping queries using the GROUP by keyword
- group Condition: The condition after grouping is used having , the condition before grouping uses where
Execution order
Select
From
where
GROUP BY
Having
ORDER BY
Limit clause
Limit is used to limit the starting line of the query result and the total number of rows
start line Calculation Formula ( current Page -1) * number of records per page
MYSQL--DQL data Query Language standard syntax