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

How does mysql query the number of occurrences of data

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

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "mysql how to query the number of times of data". In daily operation, I believe many people have doubts about how to query data in mysql. The editor consulted all kinds of information and sorted out a simple and easy-to-use method of operation. I hope it will be helpful for you to answer the doubt of "how to query data in mysql". Next, please follow the editor to study!

In mysql, select statements can be used in conjunction with group by and count to query the number of data occurrences, count can return the number of retrieved data, the syntax is "select column name, count (*) as count from table name group by column name".

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How does mysql query the number of data occurrences

The count function is a function used to count records in a table or array, and count (*) returns the number of rows retrieved, whether or not it contains a null value.

When SELECT retrieves from one table and no other columns, and there is no WHERE clause, COUNT (*) is optimized to return as fast as possible.

Examples are as follows:

Table data:

The number of times the query appears by cat_type

For the number of times the query appears by cat_type, you can use the following statement:

Select cat_type,count (*) as count from cat group by cat_type

For the number of times the query is classified by cat_type, you can use the following statement:

Select cat_type,count (*) as count from cat group by cat_type having count > 1

The query results are as follows

At this point, the study on "how to query the number of times mysql data appears" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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