当前位置: 代码迷 >> 综合 >> centos7:mysql数据库(基本SQL语句---函数)
  详细解决方案

centos7:mysql数据库(基本SQL语句---函数)

热度:9   发布时间:2023-10-18 13:10:50.0

 函数
    database()           eg. select database(); #.查看当前所在的库
    user()                   eg. select user(); #.查看当前所登录的用户
    password()          eg. update mysql.user set password=password('456') where host='localhost' and user='root';
                                        # 修改root密码,函数加密456,并且passward进行加密,调用主机名字用户为。

    聚合函数
        max() 最大值          eg. select max(math) from t2;
                                            select name,english from t2 where english=(select max(english) from t1);
        min() 最小值          eg. select min(math) from t2;
        sum() 求和             eg. select sum(math) from t2;
        avg() 平均值          eg. select avg(math) from t2;
        count() 计数          eg. select sex,count(sex) from t1 group by sex; # 统计不同性别的数量

    时间函数
        1、查看当前时间
            curtime()
                eg. select curtime();
        2、查看当前日期
            curdate()
        3、查看系统时间
            now()
            sysdate()

    其他函数
        1、连接函数 concat()
            select concat(username,uid) from pass;
            select concat(username,' ',uid) from pass;
            select concat(username,':',uid) from pass;
            select concat(username,':',uid) as 'username-uid' from pass;

        2、转换成小写 lower()
            update pass set username='ROOT' where username='root';
            select lower(username) from pass;

        3、转换成大写 upper()
            select upper(username) from pass;

        4、求长度 length()

            select username,length(username) from pass;

 

 

  相关解决方案