mysql查询语句基本用法_MySQL
一:mysql基本语句
1.显示可用数据库
show databases;
2.创建一个library数据库
create databaselibrary;
3.使用数据库
use library;
4.查看表
show tables;
5.建表语句
mysql> uselibrary;
Database changed
mysql> createtable viedos(
-> video_id int(11) not nullauto_increment,
-> title varchar(255) not null,
-> director varchar(255) not null,
-> primary key(video_id));
Query OK, 0 rowsaffected (0.30 sec)
6.插入数据
insert intoviedos(video_id,title,director)values
(1,'大上海','武打片'), (2,'小上海','爱情片'),(3,'红上海','喜剧片'),(4,'黑上海','枪打片'),(5,'大上海','散打片');
7.删除表
delete from table_name;
8.更新表数据
update viedos settitle='上海滩' where video_id=1;
二:执行查询语句
A:基本语句
1.查询全部
SELECT * FROMviedos;
2.查询部分
SELECT title FROMviedos;
3.去掉查询结果相同的部分
SELECT distinct title FROM viedos;
SELECT title FROM viedosWHERE director='武打片';
B:使用逻辑比较运算符
创建一张新表:
CREATE TABLE core(
sname VARCHAR(25)NOT NULL,
math INT NOT NULL,
physics INT NOTNULL,
literature INT NOTNULL)
插入数据
INSERT INTO coreVALUES('john',68,37,45),('jim',96,89,92),
('bill',65,12,45),('harry',68,25,82);
查询1:
SELECT * FROM coreWHERE math>90;
查询2:
SELECT sname FROMcore WHERE math>85;
查询3:
SELECT * FROM coreWHERE math
查询4:
SELECTsname,math+physics+literature FROM core;
C:使用函数查询
查询1:
SELECT COUNT(*)FROM core;
查询2:
SELECT AVG(math)FROM core;
查询3:
SELECTMIN(math),MAX(physics) FROM core;
D:筛选查询结果
查询1:降序
SELECT math FROMcore ORDER BY math DESC;
查询2:显示两条记录
SELECT math FROMcore LIMIT 2,2;
查询3:联合使用
SELECT math FROMcore ORDER BY math DESC LIMIT 2,2;
E:使用通配符查询
查询1:
SELECT sname FROMcore WHERE sname LIKE '%j%';
查询2:
SELECT math FROMcore WHERE math LIKE '%6%';

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



With the development of web applications, PHP language has been widely used in web development. In the PHP8.0 version, a new language feature was introduced - the multi-catch statement. What is a multi-catch statement? In previous PHP versions, developers needed to write multiple catch statements to handle multiple exception types. For example, the following code block shows the handling of two different exceptions: try{//Somecodethatmay

Python is a widely used high-level programming language. It is easy to learn, efficient and flexible, and is deeply loved by developers. In Python, flow control statements are an important part of implementing program logic. This article will introduce commonly used flow control statements in Python and provide code examples to deepen understanding. In Python, common flow control statements include conditional statements and loop statements. Conditional statements execute different code blocks based on the true or false condition and are used to determine and select execution branches. The loop statement is used to repeat

How to implement the statement of inserting data in MySQL? When using a MySQL database, inserting data is a very basic and common operation. By inserting data, new records can be added to database tables to provide support for business operations. This article will introduce how to use the INSERT statement in MySQL to implement data insertion operations, and provide specific code examples. The INSERT statement in MySQL is used to insert new records into the database table. Its basic syntax format is as follows: INSERTINTOt

How to implement the statement to unlock the table in MySQL? In MySQL, table locks are a commonly used locking mechanism used to protect data integrity and consistency. When a transaction is reading and writing to a table, other transactions cannot modify the table. This locking mechanism ensures data consistency to a certain extent, but may also cause other transactions to be blocked. Therefore, if a transaction cannot continue for some reason, we need to manually unlock the table so that other transactions can continue. MySQL provides a variety of

MySQL is a commonly used relational database system used to manage and store data. In MySQL, user passwords are one of the important factors in protecting database security. In daily management of the database, it is often necessary to change the user's password to ensure the security of the database. So, how to implement the statement of changing user password in MySQL? This article will provide you with specific code examples. Change the MySQL user password through the ALTERUSER statement. The ALTERUSER statement is MySQL8.0 and above.

How to implement the statement to create a table in MySQL? In the MySQL database, creating a table is one of the most important operations. The statement to create a table needs to take into account various factors such as the table structure, field types, constraints, etc. to ensure the accuracy and completeness of data storage. The following will introduce in detail how to create a table statement in MySQL, including specific code examples. First, we need to connect to the MySQL database server. You can use the following command to connect: mysql-uusername-p Next, enter the password

The function of the SQL ALTER statement requires specific code examples. In a database management system, the ALTER statement is a SQL command used to modify database objects. Through the ALTER statement, we can modify database objects such as tables, columns, indexes, and views, including adding, deleting, modifying, and other operations. The following will introduce the common usage of the ALTER statement in detail and provide relevant code examples. ALTERTABLE statement is used to modify the structure of the table. You can add, delete, modify columns, constraints, indexes, etc.

How to implement the statement to revoke user permissions in MySQL? In MySQL database, we often need to manage user permissions. However, sometimes we may need to revoke the permissions of certain users to ensure the security of the database. This article will introduce how to use specific code examples to implement the method of revoking user permissions in MySQL. First, we need to log in to the MySQL database server and switch to a user with sufficient permissions, such as root. We can then use the REVOKE statement to reclaim the user
