当前位置:网站首页>通过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值,可用于数字、字符和日期时间列。
边栏推荐
- Matrix keyboard scan (keil5)
- Unforgettable summary of 2021
- Simple use of timeunit
- MySql——存储引擎
- Explain STM32 startup file in detail
- Use go language to read TXT file and write it into Excel
- Using C language to realize IIC driver in STM32 development
- Oracle triggers and packages
- Clickhouse database installation deployment and remote IP access
- Cookie operation
猜你喜欢
Oracle triggers and packages
Today, share the wonderful and beautiful theme of idea + website address
Light up the running light, rough notes for beginners (1)
QT small case "addition calculator"
How to modify the file path of Jupiter notebook under miniconda
HDU1231 最大连续子序列(分治or动规or双指针)
Nombre - 1. Création de tableaux
The folder directly enters CMD mode, with the same folder location
剑指 Offer 56 数组中数字出现的次数(异或)
Don't confuse the use difference between series / and / *
随机推荐
Readme, self study record
Numpy——1.數組的創建
Cygwin installation
CADD course learning (5) -- Construction of chemosynthesis structure with known target (ChemDraw)
String alignment method, self use, synthesis, newrlcjust
GBK error in web page Chinese display (print, etc.), solution
HDU1231 最大连续子序列(分治or动规or双指针)
TCP and UDP
GPIO circuit principle of stm32
Mouse click fireworks explosion effect
Microservice registry Nacos introduction
Play with grpc - go deep into concepts and principles
Don't confuse the use difference between series / and / *
Idea to view the source code of jar package and some shortcut keys (necessary for reading the source code)
How to deal with excessive memory occupation of idea and Google browser
Let me teach you how to develop a graphic editor
With the help of Navicat for MySQL software, the data of a database table in different or the same database link is copied to another database table
(top) pretty girl binary color code portal
RF ride side door processing of prompt box
2022年PMP项目管理考试敏捷知识点(7)