Game test-database Statement 1, test database Statement 1

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.