Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MYSQL Learning Series-- DML sentences (2)

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Introduction:

Data manipulation language (Data Manipulation Language, DML) is a set of instructions responsible for running data access to database objects in SQL language. With INSERT, UPDATE and DELETE instructions as the core, they represent insert, update and delete respectively. They are instructions that must be used in the development of data-centric applications.

Practical operation

This article is a continuation of the previous update, the previous article: MYSQL Learning Series-- DML sentences (1)

Last time we talked about inserting, updating and deleting records respectively. In this article, we will introduce the different ways to query (involving some common functions).

4) query records

Select field from table name

1 > query records that are not duplicated

Here we use the database that comes with mysql to demonstrate (information_schema)

First of all, we need use, the database use information_schema.

Then query select COLUMN_NAME from COLUMNS

Generally use distinct, filter only one field! This is when it's on a single table.

Select distinct COLUMN_NAME from COLUMNS

There are still a lot of records, but you will find that they will not be repeated as before.

2 > conditional query

Note: conditional field comparison symbols:

=, > =, sort and limit

Syntax: sorting of order by field names

We first disrupt the order of the data, and then sort them

Asc: from low to high, is also the default value

Desc: from top to bottom

Sort multiple fields

Restrictions:

Add the limit number 1 and the number 2 at the end of the statement to limit the number of queries.

The limit number 1, the number 2, the number 1 represents the record from which to start (starting at 0), and the number 2 represents the number of entries to be taken!

4 > aggregation

① sum summation

Select sum (field name) from table name

Total number of ② count records

Select count (* | Field name) from table name

③ max maximum

Select max (field name) from table name

④ min minimum

Select min (field name) from table name

⑤ GROUP BY classified aggregation

Select sum (number), Name from student group by Name

The results of ⑥ WITH ROLLUP classification aggregation are summarized again.

Select sum (number) from student group by Name with rollup

⑦ HAVING

Note: the difference between having and where is that having conditionally filters the aggregated results, while where filters the records before aggregation and should filter the records as much as possible!

You can do your own Baidu research if you don't understand! Or leave me a message.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report