• 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的值

  • 相关阅读:
    仿热血江湖游戏类45method_1、method_2
    为什么我学了 6 个月 Python,还是找不到工作?
    Servlet
    Java 实例:删除字符串中的一个字符和字符串替换
    【附源码】计算机毕业设计JAVA房产客户信息管理系统
    Unity3d+GameFramework:资源分析,资源依赖,循环依赖检测
    Vue 路由
    基于YOLO实现的口罩佩戴检测 - python opemcv 深度学习 计算机竞赛
    Java连接kubernates集群最优雅的两种方式
    C++官网 Tutorials C++ Language Basics of C++:Variables and types
  • 原文地址:https://blog.csdn.net/qq_56101220/article/details/126262368