Article Directory
Brief 1. DQL
Data Query LANGUAGE: Data Query Language
- All queries are using it SELECT
- Simple queries, complex queries can do it ~
- Database in the core language, the most important statement
- The most frequently used statement
SELECT full syntax
Note: [] represents optionally, {} represents Required
2. Specify the query field
(1) query all of the student
syntax: SELECT * FROM table
(2) query specified field
syntax: SELECT fields FROM table
(3) alias, to the result of a name
AS can play to field alias, can also play an alias to the table
syntax: SELECT field 1 AS alias 1, field 2 AS alias 2 FROM table name AS alias
(4) function Concat (a, B)
(. 5) to re distinct
functions: removing SELECT query out of the results of duplicate data, duplicate data show that only one
- All queries test scores
- Discover what the students took the exam
- Found duplicate data, deduplication
(6) database columns (expression)
- Query system version (Function)
- Used to calculate the (expression)
- Query increment step size (variable)
- Student test scores + 1 points View
Note that
the database expressions: text value column, Null, function calculation expression system variables ....
SELECT expression from table
3. where conditional clause
Action: retrieve data values meet the conditions
of the condition search by one or more expressions! Boolean result
(1) logical operators
try to use letters
- Queries test scores between 95 to 100 points
- Fuzzy query (section)
- In addition to students outside the student achievement No. 1000
(2) fuzzy query: Comparison operators
-
Query students surnamed Liu, combined with like% (on behalf of 0 to any number of characters)
-
Query students surnamed Liu, _ back (a character) name is only one word
-
Query students surnamed Liu, __ behind (a character) name only two words
-
Middle name query word Ka Ka% of students%
-
Query No. 1001, students
-
Queries students in Anhui
-
Queries address is empty student null ''
-
Queries date of birth of students is not empty
4. Union-table query
-
JOIN contrast
-
Between the three types
-
Exercise 1
Query took the exam students: Student ID, name, account number, fractional
thinking ① demand analysis, which analyzes the query from the table field, (join queries)
② determine which connection to use the query? 7 kinds
③ determining intersection points (the two data tables which are the same)
④ determined by: the student studentNo = Table transcript studentNo
- English II
Inquired the students take the exam information: school, student name, account name, scores
ideas ① demand analysis, field analysis from which the query tables, student, result, subject (join queries)
② determine which connection to use the query? 7 kinds
③ determining intersection points (the two data tables which are the same)
④ determined by: the student studentNo = Table transcript studentNo
Summary: I have to find ... what data the SELECT
the FROM table from which to search several tables
Table XXX Join connected
on cross-conditionality
assume the existence of a multiple-table query, slowly, to query two tables and then slowly increase
The paging and sorting
(1) Sort
- ASC ASC, descending DESC
- ORDER BY sorting through which field, how row
- Exercise: results of the query results sorted in descending order
(2) Paging
Paging reasons: to ease the pressure database, gives the experience better, waterfall
syntax: limit the starting value, page size
N-page limit (the n--1) * pageSize, pageSize
(the n--1) * pageSize : start value
the pageSize: page size
n: this page
total data / page = total number of pages
6. subquery
Essence: nested in the where clause in a subquery
-
Exercise 1: query the database structure of all test results-1 (student number, account number, grades), in descending order
Method 1: Use join queries
way: using sub-queries (from the inside and outside)
-
Exercise Two: Queries courses for advanced mathematics -2 and no score is not less than 80 students of the school number and name of the
Way: Use join queries
way: using sub-queries (from the inside and outside)
7. packet filtering and
Core: grouped according to different courses
the GROUP BY ...
the HAVING ...
Exercise: Query different courses average, highest score, lowest score, on average more than 80 points