Game test-database Statement 1, test database Statement 1
Select id, name, energy from db_name where engrgy between '000000' and '000000'
To sort the output content once, use order by asc to change from small to large to desc.
Select id, name, energy from db_name where engrgy between '000000' and '000000' order by energy asc
100 and 201 are arranged in ascending order.
The column name after order by can also be sorted by the number of the column in the query result. This result starts from 1.
Select id, name, energy from db_name where engrgy between '000000' and '000000' order by 3 asc
Query the preceding function that calculates the sum of engrgy in one query interval using SQL functions.
Select id, name, energy from db_name where engrgy between '000000' and '000000' order by 3 asc change statement
Select id, name, sum (energy) from db_name where engrgy between '000000' and '000000' order by 3 asc
The same is true for max.
Select id, name, max (energy) from db_name where engrgy between '000000' and '000000' order by 3 asc
You can also view several conditions at the same time, but the id and name are invalid at this time.
The query result does not change.
Select id, name, max (energy), min (energy), avg (energy) from db_name where engrgy between '000000' and '000000' order by 3 asc
The test needs to know what key fields you need to query
Still use energy
You can also view the number of lines in the output table.
Select id, name, count (energy) from db_name where engrgy between '000000' and '000000' order by 3 asc
The output result is
Id name count (energy)
Designed to function
Id is unique here, so it is not suitable. Here, we want to change the rule id to appear multiple times but associate with the name
Select id, name, sum (energy) from db_name group by id
Adds the physical strength of the same id.
The extended energy of more than 1000 is listed as follows:
Because Function
Select id, name, sum (energy) from db_name group by id having sum (energy)> 1000
Multi-Table query
We need to check the relevance between the two Arena db_arena and the user table db_role.
Locate the unique field id
Sort by rank
Select role. id, role. name, arena. rank, role. name, role. energy from db_arena arena, db_role role where role. id = arena. id group bu bank
The input result contains two tables.