• mysql 内部函数


      

    1. group_concat 

      返回一个字符串结果,该结果由分组中的值连接组合而成。

      函数语法:

        group_concat( [DISTINCT] 要连接的字段 [Order BY 排序字段 ASC/DESC] [Separator ‘分隔符’] )

          案例:

        数据:

                  

    以id分组,把price字段的值在同一行打印出来,逗号分隔(默认)
    SELECT id,group_concat(price) from price group by id;

        

    替换,分隔
    SELECT id,group_concat(price separator  '#') from price group by id;
    

      

     问题:

        1. GROUP_CONCAT有个最大长度的限制,超过最大长度就会被截断掉,你可以通过下面的语句获得:

          SELECT @@global.group_concat_max_len;

          show variables like "group_concat_max_len";

        2.在MySQL配置文件中my.conf或my.ini中添加:

          #[mysqld]
          group_concat_max_len=102400

        3.重启MySQL服务

    2.replace

      replace函数直接替换mysql数据库中某字段中的特定字符串,不再需要自己写函数去替换

      语法: replace (`field_name`,’from_str’,'to_str’)

      

    3.  DATE_FORMAT(date , format)

       函数用于以不同的格式显示日期/时间数据。

      常见formate :  https://www.w3school.com.cn/sql/func_date_format.asp

      

    4.string 《-------》date

    date----->string

      date_format(date , format)

      

     string---->date

      str_to_date(string,format)

      

    5.

    作者:crazyLL
    纯粹自己记录着玩的,来源于自己的想法或者互联网文章,侵删
  • 相关阅读:
    如何将Python项目发布到PyPI
    hashlib的md5计算
    使用hexo和coding建立静态博客站点
    mysql 使用记录
    linux QA
    linux 使用记录
    转载-linux内核长什么样
    mysql 更改默认字符集
    Say goodbye
    SSH proxycommand 不在同一局域网的机器ssh直连
  • 原文地址:https://www.cnblogs.com/crazy-lc/p/15008848.html
Copyright © 2020-2023  润新知