• MySQL——内置函数


    1 聚合函数

    纵向统计,把一张表的某一列的多行聚合在一起,将同类别或具有相同特征的数据进行聚合处理,函数结果也可以直接取别名

    select count([distinct ]columnname) from tablename;// null不计入
    // 以下只对数字有意义
    select sum([distinct ]columnname) from tablename;
    select avg([distinct ]columnname) from tablename;
    select max([distinct ]columnname) from tablename;
    select min([distinct ]columnname) from tablename;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    2 日期函数

    在这里插入图片描述

    date_add(date,intervall d_value_type):给date加上d_value(年/////秒,由type决定)
    date_sub同上
    datediff计算日期差
    
    • 1
    • 2
    • 3
    mysql> select now();
    +---------------------+
    | now()               |
    +---------------------+
    | 2022-08-13 22:53:47 |
    +---------------------+
    
    mysql> select current_timestamp();
    +---------------------+
    | current_timestamp() |
    +---------------------+
    | 2022-08-13 22:54:13 |
    +---------------------+
    
    mysql> select current_date();
    +----------------+
    | current_date() |
    +----------------+
    | 2022-08-13     |
    +----------------+
    
    mysql> select current_time();
    +----------------+
    | current_time() |
    +----------------+
    | 22:54:51       |
    +----------------+
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    mysql> create table if not exists tfundate( id int unsigned primary key auto_increment, birth date not null )engine=innodb default charset=utf8;
    
    mysql> insert into tfundate (birth) values ('2000-01-01'); // 手动插入时间
    mysql> insert into tfundate (birth) values (current_date()); // 当前时间
    mysql> select * from tfundate;
    +----+------------+
    | id | birth      |
    +----+------------+
    |  1 | 2000-01-01 |
    |  2 | 2022-08-12 |
    +----+------------+
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    3 字符串函数

    在这里插入图片描述
    length函数返回字符串长度,以字节为单位

    4 数学函数

    在这里插入图片描述

    5 其他函数

    5.1 user()

    查询当前用户

    5.2 md5(str)

    对一个字符串进行md5摘要,摘要后得到一个32位字符串

    5.3 database()

    显示当前正在使用的数据库

    5.4 password(用户名)

    MySQL数据库使用该函数对用户加密

    5.5 ifnull(val1, val2)

    如果val1为null,返回val2,否则返回val1的值

  • 相关阅读:
    Windows和Linux上使用Prometheus+Grafana监控Springboot
    如何使用 docker 部署前端
    使用POI和EasyExcel实现Excel导入和导出功能
    京东18A整理出最牛《Spring技术内幕》,深入解析Spring原理
    Linux:ssh免密登陆
    ESP32网络开发实例-Web服务器控制GPIO
    mysql面试题26:MySQL中什么是MVCC,它的底层原理是什么
    第三章:人工智能深度学习教程-基础神经网络(第一节-ANN 和 BNN 的区别)
    创建对象在堆区如何分配内存
    Linux ping向网络主机发送ICMP ECHO REQUEST
  • 原文地址:https://blog.csdn.net/qq_56101220/article/details/126262368