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

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

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

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

The usage of try statement in C# requires specific code examples. C# is an object-oriented programming language, in which the try statement is a structure used to capture and handle exceptions. Through the try statement, we can write code to handle exceptions that may occur, thereby improving the stability and reliability of the program. In this article, we will introduce the usage of try statement in C# and provide some specific code examples to help readers understand. In C#, the try statement consists of try block, catch block and optionalfina

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

Using Go statements in C language is a common and flexible programming technique that can achieve concurrent execution. The following will introduce some techniques for mastering Go statements in C language, with specific code examples. First, we need to understand how to simulate concurrent execution in C language. In C language, concurrent operations can be achieved by creating multiple threads. In multi-threaded programming, we can use the pthread library to create and manage threads. Next is a simple C language program in which two threads are created and executed concurrently

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

To learn Python from scratch, first understand the types of flow control statements! Python is a simple and powerful programming language that is widely used in data analysis, artificial intelligence, network development and various scientific computing fields. As a beginner, it is very important to master basic flow control statements, because they are the basis for realizing logical judgment and controlling the program execution flow. In Python, there are three main types of flow control statements: sequential structures, conditional structures and loop structures. The following will introduce these three process control statements in detail and give the corresponding

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.
