当前位置:网站首页>通过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值,可用于数字、字符和日期时间列。
边栏推荐
- Basic operation of external interrupt (keil5)
- Latex notes
- 2022 PMP project management examination agile knowledge points (7)
- I 用c l 栈与队列的相互实现
- Unforgettable summary of 2021
- assert_ Usage of param function
- Idea common settings
- Efficiency difference: the add method used by the set directly and the add method used by the set after judgment
- And let's play dynamic proxy (extreme depth version)
- Temperature sensor DS18B20 principle, with STM32 routine code
猜你喜欢

The mutual realization of C L stack and queue in I

Rough notes of C language (2) -- constants

CADD course learning (6) -- obtain the existing virtual compound library (drugbank, zinc)

2022年PMP项目管理考试敏捷知识点(7)

HDU1231 最大连续子序列(分治or动规or双指针)

Ugnx12.0 initialization crash, initialization error (-15)

How to delete the virus of inserting USB flash disk copy of shortcut to

What is Bezier curve? How to draw third-order Bezier curve with canvas?

借助 Navicat for MySQL 软件 把 不同或者相同数据库链接中的某数据库表数据 复制到 另一个数据库表中

Latex notes
随机推荐
Function of static
The sublime version that XP can run is 3114
Cookie operation
Opendrive record
Self summary of college life - freshman
Simple operation of running water lamp (keil5)
HDU1232 畅通工程(并查集)
Numpy——1.數組的創建
Typecho adds Baidu collection (automatic API submission plug-in and crawler protocol)
II Simple NSIS installation package
HDU1231 最大连续子序列(分治or动规or双指针)
QT small case "addition calculator"
Day06 class variables instance variables local variables constant variables naming conventions
Matrix keyboard scan (keil5)
Build your own random wallpaper API for free
Butterfly theme beautification - Page frosted glass effect
Exit of pyGame, idle and pycharm
cygwin
Using GEE plug-in in QGIS
Could NOT find XXX (missing: XXX_LIBRARY XXX_DIR)