Restricted query and sorting display (Chapter Summary), Chapter Summary
1. Standard data query syntax.
SELECT [DISTINCT] * | column [AS] [alias], column [AS] [alias],...
FROM table name [alias]
[WHERE condition (s)]
[Order by sorting field [ASC | DESC] [, sorting field [ASC | DESC]...];
2. The execution sequence of multiple statements is FROM, WHERE, SELECT, and order by. The order by statements are always placed in the final execution.
3. When using a restricted query, several conditions described are relational operations, logical operations, BETWEEN... AND, LIKE, IN, and null.
4. The order by clause can sort the query results. The order by clause must unmount the end of all query statements.
Sorting of SQL queries
Select * from table where field in (x1, x2, x3, x4......) order by field ASC/DESC
In this example, the sorting field is the field in the index condition, ASC is in ascending order, and DESC is in descending order. The sorting in this example is X1, X2, X3, but X1 may have a lot of data, if sorting is performed within X1, add the second sorting.
Select * from table where field in (x1, x2, x3, x4......) order by field ASC/DESC, Field 2 ASC/DESC
This expression is sorted by Field 2 based on the order of X1 and X2!
I don't understand how multi-data, X1, X2, and so on contain multiple records, so you don't want to use Group?
Let's take a look at the use of group by. You can limit the grouping conditions. The keyword is having. The method class where is used, but it is different from where!
SQL query statement: Random, sorted, and limit the number of repetitions of a column
SELECT a. name, a. class FROM student AS
WHERE a. name IN (select top 5 name FROM student WHERE class = a. class)
Order by class
Oh. Sorry, please try the following methods.
SELECT a. name, a. class FROM student AS
WHERE a. name IN (select top 5 name FROM student WHERE class = a. class order by class DESC/ASC, UUID () DESC/ASC limit 0, 5)
Order by class