当前位置:网站首页>通过sql语句统计特定字段出现次数并排序
通过sql语句统计特定字段出现次数并排序
2022-07-05 07:38:00 【qq_29566629】
select log_ip, count(*) as number from tp_admin_log group by log_ip order by number desc
实现的功能是统计tp_admin_log表里log_ip字段各个值出现的次数并按降序排序。
ps:
要注意的是,group by函数一般要和聚合函数,比如count()函数一起使用
常用的聚合函数有:COUNT(),SUM(),AVG(),MIN(),MAX()。
COUNT(),其作用主要是返回每个组的行数,也会返回有NULL值的列,可用于数字和字符列。
SUM(),主要用于返回表达式中所有的总和,忽略NULL值,仅用于数字列。
AVG(),返回表达式所有的平均值,仅用于数字列并且自动忽略NULL值。
MIN(),返回表达式中的最小值,忽略NULL值,可用于数字、字符和日期时间列。
MAX(),返回表达式中的最大值,忽略NULL值,可用于数字、字符和日期时间列。
边栏推荐
- Self summary of college life - freshman
- Professional knowledge of public security -- teacher bilitong
- II Simple NSIS installation package
- I can't stand the common annotations of idea anymore
- Deepin, help ('command ') output saved to file
- Good websites need to be read carefully
- Using C language to realize IIC driver in STM32 development
- GBK error in web page Chinese display (print, etc.), solution
- repo. conda. An example of COM path error
- Function and usage of function pointer
猜你喜欢
Pagoda create multiple sites with one server
CADD课程学习(6)-- 获得已有的虚拟化合物库(Drugbank、ZINC)
CADD课程学习(5)-- 构建靶点已知的化合结构(ChemDraw)
arcgis_ spatialjoin
Set theory of Discrete Mathematics (I)
Thunderbird tutorial \ easy to use mail client
Detailed explanation of miracast Technology (I): Wi Fi display
From then on, I understand convolutional neural network (CNN)
Latex notes
Idea to view the source code of jar package and some shortcut keys (necessary for reading the source code)
随机推荐
The mutual realization of C L stack and queue in I
Simple use of timeunit
611. Number of effective triangles
I 用c I 实现队列
editplus
The sublime version that XP can run is 3114
[untitled]
Don't confuse the use difference between series / and / *
MySql——存储引擎
(tool use) how to make the system automatically match and associate to database fields by importing MySQL from idea and writing SQL statements
Web page Chinese display (print, etc.) GBK error, solution, software
Self summary of college life - freshman
Build your own random wallpaper API for free
II Simple NSIS installation package
Eclipse project recompile, clear cache
公安专业知识--哔哩桐老师
数字孪生实际应用案例-风机篇
PIL's image tool image reduction and splicing.
GPIO circuit principle of stm32
The golang timer uses the stepped pit: the timer is executed once a day