Simple example: how to use MySQL database series _ PHP Tutorial

Source: Internet
Author: User
For more information, see SQL database series. StructuredQueryLanguage. This language allows us to perform complex operations on the database. The SQL language is widely used. Many databases SQLIs the abbreviation of the Structured Query Language. This language allows us DatabasePerform complex operations. The SQL language is widely used. Many database products support the SQL language, which means that if we have learned the SQL language, we can apply this knowledge to MS Access or SQL Server, Oracle, DB2, and many other databases.
 
SQL is used in relational databases. A relational database stores data in tables (also called links. Each database is mainly composed of a group of tables. Each table is composed of a group of records. each record has the same structure in the table and contains a fixed number of fields with certain types.
 
  
Next we will look at a table in the actual database. The table name is cia, which contains more than 250 Records. each record represents a country. The table consists of five fields with some values StringType.
Name region area population gdp
-------------------------------------
Yemen Middle East 527970 14728474
Za ire Africa 2345410 44060636 18800000000
Zambia Africa 752610 9445723 7900000000
Zimbabwe Africa 390580 11139961 17400000000
Below we can use some SQL statements to query the data we are interested in this table.
1. what is China's GDP?
The SQL statement used for query is:
Select gdp from cia where name = 'China'
The query result is:
4800000000000
2. shows the number of countries and total population in each region. And sorted by the number of people in the region from large to small.
The SQL statement used for query is:
SELECT region, COUNT (name), SUM (population)
FROM cia
Group by region
Order by 3 DESC
The query result is:
Region COUNT (name) SUM (population)
--------------------------------
Asia 14 2963031109
Africa 59 793382933
Europe 43 580590872
....
How about it? I have a basic understanding of the SQL language. I also have a rough understanding of a series of common feelings in the SQL language, such as databases, tables, records, and fields. If it is not clear, it doesn't matter. in the following content, we will gradually introduce the simplest content in the SQL language and provide a wide range of exercises for you to perform. I believe that this series has been completed Tutorial, You can become a master of SQL language.
Before introducing the group by and HAVING clauses, we must first talk about a special function in SQL: aggregate function, such as SUM, COUNT, MAX, and AVG. The fundamental difference between these functions and other functions is that they generally work on multiple records.

Http://www.bkjia.com/PHPjc/630966.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/630966.htmlTechArticleSQL is short for Structured Query Language. This language allows us to perform complex operations on the database. The SQL language is widely used. Many databases...

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.