


About MySQL database A collection of add, delete, modify and query statements
1. Basic sql statements
CRUD操作: create 创建(添加) read 读取 update 修改 delete 删除
1. Add data
insert into Info values('p009','张三',1,'n001','2016-8-30 12:9:8') ; 给特定的列添加数据 insert into Info (code,name) values('p010','李四'); 自增长列的处理 insert into family values('','p001','数据','T001','数据',1); insert into 表名 values(值)
2. Delete data
删除所有数据 delete from family 删除特定的数据 delete from Info where code='p001' delete from 表名 where 条件
3. Modify data
修改所有数据 update Info set name='徐业鹏' 修改特定数据 update Info set name='吕永乐' where code='p002' 修改多列 update Info set name='吕永乐',sex=1 where code='p003' update 表名 set 要修改的内容 where 条件 tno =
4. Read data
(1)简单读取,查询所有列(*) 所有行(没有加条件) select * from Info (2)读取特定列 select code,name,class from Info (3)条件查询 select * from Info where code='p003' (4)多条件查询 select * from Info where code='p003' or nation='n002' #或的关系 select * from Info where sex=0 and nation='n002' #与的关系 (5)关键字查询(模糊查询) 查所有包含奥迪的汽车 select * from car where name like '%奥迪%'; #百分号%代表任意多个字符 查以'皇冠'开头的所有汽车 select * from car where name like '皇冠%'; 查询汽车名称中第二个字符是'马'的 select * from car where name like '_马%'; #下划线_代表任意一个字符 (6)排序查询 select * from car order by powers #默认升序排列 select * from car order by powers #升序asc 降序 desc 先按brand升序排,再按照price降序排 select * from car order by brand,price desc
(7) Range query
select * from car where price9()>40 and price<60 select * from car where price between 40 and 60
(8) Discrete query
select * from car where price=30 or price=40 or price=50 or price=60; select * from car where price in(30,40,50,60)取出数据 select * from car where price not in(30,40,50,60)去掉数据
(9) Aggregation function (statistical query)
select count(*) from car select count(code) from car #取所有的数据条数 select sum(price) from car #求价格总和 select avg(price) from car #求价格的平均值 select max(price) from car #求最大值 select min(price) from car #求最小值
(10)Paging query
select * from car limit 0,10 #分页查询,跳过几条数据(0)取几条(10) 规定一个每页显示的条数:m 当前页数:n] select * from car limit (n-1)*m,m
(11) Deduplication query
select distinct brand from car
(12) Group query
Query the number of cars in each series in the car table
select brand,count(*) from car group by brand
After grouping, only this column or aggregate function can be queried
Get the series code where the average price of the series is greater than 40
select brand from car group by brand having(加条件) avg(price)>40
Get the series code where the maximum fuel consumption of the series is greater than 8
select brand from car group by brand having max(oil)>8
2. Advanced query of MySql (Use external connection
)
Connection query
SELECT t1.Name,t2.Brand_Name FROM brand t2,car t1 -- 笛卡尔乘积 WHERE t2.Brand = t1.Brand
--Multi-table join query
SELECT t1.Name,t2.Brand_Name,t3.prod_name FROM car t1 LEFT JOIN brand t2 ON t1.Brand = t2.Brand LEFT JOIN productor t3 ON t2.Prod = t3.Prod
--The number of fields in joint query must be the same
SELECT `Name`,Price FROM car UNION SELECT Brand_Name,Brand_Memo FROM brand -- 子查询(***) SELECT * FROM car WHERE car.brand in (SELECT Brand FROM brand WHERE Prod = 'p001')
Description: Use outer join
##A、left
(outer
)
join
:
Left outer join (Left join): The result set includes matching rows of the join table and all rows of the left join table.
SQL: select
a.a, a.b, a.c, b.c, b.d, b.f from
a LEFT
OUT
JOIN
b ON
a.a = b.c
##B:right
(
outer
)
join
:
Right outer join (right join): The result set includes both the matching join rows of the join table and all rows of the right join table.
##C:full/
cross
(outer
)
join
:
Full outer join: not only includes matching rows of the symbolic connection table, but also includes all records in the two connected tables.
Group:Group by
:
<span style="font-size: 16px"><strong></strong></span>A table , once the grouping is completed, only group-related information can be obtained after querying.
##Group related information: (Statistical information) count,
sum
,
max
,
min
,
avg
Standards for grouping)
<p class="line number60 index59 alt1"><span style="font-size: 16px"><strong><code class="sql spaces">
The fields in the selecte statistical function cannot be placed together with ordinary fields;
E:Outer join query (table name 1: a table name 2: b)
##select
a.a, a.b, a.c, b.c, b.d, b.f from
a LEFT
OUT
JOIN
b ON
a.a = b.c
F: The usage of between
,
between
includes boundary values when limiting the query data range,
not
betweenNot including
##select *
from
table1
where
time
between
time1
and
time2
##select a,b,c, from
table1 where
a not
between
Value 1 and
Value 2
Four-table joint query problem: ##select
* from
a left
inner
join
b on
a.a=b.b right
inner
join
c on
a.a=c.c inner
join
d on
a.a=d.d where
....H:
##select
10 * form table1 where
Range
I:Select all the information of the record with the largest a in each group of data with the same b value (can be used for monthly forum rankings, monthly hot-selling product analysis, by subject Score ranking, etc.)
select
a,b,c
from
tablename ta
where
a=(
select
max
(a)
from
tablename tb
where
tb.b=ta.b)
The above is the detailed content of About MySQL database A collection of add, delete, modify and query statements. For more information, please follow other related articles on the PHP Chinese website!

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.