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