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 to realize data Counting with SQL

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article will explain in detail how to achieve data counting in SQL. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Use count syntax and as syntax for counting in SQL, for example, count the name fields in the following table.

Namecore Wang 51 Xiao Wei 61 Xiao Zhang 71 Xiao Li 51 Xiao Wang 51 select name,count (name) as total FROM tbl_name group by` name

Count (name) generates a new field, as names the newly generated count field, group by means to count separately, and the output is as follows

Nametotal Xiao Zhang 1 Xiao Li 1 Xiao Wang 2 Xiao Wei 1

The group by syntax in SQL makes sense only when used in conjunction with the count syntax.

"group by" is to group the data, and then calculate each group separately, usually combined with the aggregate function (as shown in the following figure).

Function function sum (column name) summation max (column name) maximum min (column name) minimum avg (column name) average count (column name) statistics on the number of records on "SQL how to achieve data counting" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

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

Servers

Wechat

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

12
Report