当前位置:网站首页>通过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值,可用于数字、字符和日期时间列。
边栏推荐
- Exit of pyGame, idle and pycharm
- And let's play dynamic proxy (extreme depth version)
- 玩转gRPC—深入概念与原理
- Rough notes of C language (2) -- constants
- msys2
- Ggplot2 drawing learning notes in R
- The sublime version that XP can run is 3114
- Today, share the wonderful and beautiful theme of idea + website address
- Distinction between heap and stack
- Function and usage of function pointer
猜你喜欢
SQL JOINS
剑指 Offer 56 数组中数字出现的次数(异或)
2022 PMP project management examination agile knowledge points (7)
How to modify the file path of Jupiter notebook under miniconda
When jupyter notebook is encountered, erroe appears in the name and is not output after running, but an empty line of code is added downward, and [] is empty
What is deep learning?
Differences between pycharm and idle and process -- join() in vs Code
数字孪生实际应用案例-风机篇
Could NOT find XXX (missing: XXX_LIBRARY XXX_DIR)
[neo4j] common operations of neo4j cypher and py2neo
随机推荐
Function of static
Graduation thesis project local deployment practice
Close of office 365 reading
Ue5 hot update - remote server automatic download and version detection (simplehotupdate)
Use stm32cubemx tool to write the demo program of FreeRTOS
[neo4j] common operations of neo4j cypher and py2neo
RF ride side door processing of prompt box
Package ‘*****‘ has no installation candidate
(tool use) how to make the system automatically match and associate to database fields by importing MySQL from idea and writing SQL statements
611. 有效三角形的个数
Matrix keyboard scan (keil5)
GPIO circuit principle of stm32
Batch modify the txt file code to UTF-8 (notepad++)
Batch convert txt to excel format
And let's play dynamic proxy (extreme depth version)
list. files: List the Files in a Directory/Folder
Deepin, help ('command ') output saved to file
Rough notes of C language (2) -- constants
行测--资料分析--fb--高照老师
RTOS in the development of STM32 single chip microcomputer