SQL database usage series_PHP tutorial

WBOY
Release: 2016-07-13 17:03:23
Original
1028 people have browsed it

SQL is the abbreviation of Structured Query Language. This language allows us to perform complex operations on databases. The SQL language is used in a very wide range of applications. Many database products support SQL language, which means that if we learn SQL language, we can apply this knowledge to MS Access or SQL Server, Oracle, DB2 and many more in other databases.

SQL language is used in relational databases. A relational database stores data in tables (also called relationships). The main component of every database is a set of tables. Each table is composed of a set of records - each record has the same structure in the table, containing a fixed number of fields of a certain type.


Let’s take a look at a table in an actual database. The table is named cia and contains more than 250 records, each representing a country. The table consists of 5 fields. Some of the field values ​​are string type, and some are numeric types.
name region area population gdp
---- ------ ------ ---------- -----------
Yemen Middle East 527970 14728474 23400000000
Zaire Africa 2345410 44060636 18800000000
Zambia Africa 752610 9445723 7900000000
Zimbabwe Africa 39 0580 11139961 17400000000
Next we can use some SQL statements to query what we are interested in in this table data.
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. Give the number of countries and total population in each region . And sorted by region's population from most to least.
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 you, now you have a basic understanding of the SQL language, and at the same time have a good understanding of databases, tables, records, fields, etc. I also have a general understanding of the series of expressions commonly used in SQL language. It doesn’t matter if it’s not very clear. In the following content, we will gradually introduce it to you from the simplest content in the SQL language, and provide a wealth of exercises for you to practice. I believe that after studying this series of tutorials, 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 the SQL language: aggregate functions, such as SUM, COUNT, MAX, AVG, etc. The fundamental difference between these functions and other functions is that they generally operate on multiple records.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630966.htmlTechArticleSQL is the abbreviation of Structured Query Language. This language allows us to perform complex operations on the database. The SQL language is used in a very wide range of applications. Many databases...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template