zoukankan      html  css  js  c++  java
  • mysql常用方法学习

    环境

      

    create table phople (
        id int(11) not null primary key auto_increment,
        name char(20) not null,
        sex int(1) not null default '0',
        degree double(16, 2)
    );
    
    insert into phople value (null, 'zh', '0', '0');
    
    insert into phople value (null, 'az', '1', '22');
    insert into phople value (null, 'aa', '1', '33');
    insert into phople value (null, 'ad', '1', '44');
    

    1. select group_concat(name) from phople;                      ## 直接把所有的name字段值链接起来。  

      运行结果: zh,az,aa,ad

        select group_concat(name) from phople group by sex;  ## 根据sex分组后。把分组的name字段相连接起来。

      运行结果: 

          zh

          az,aa,ad

         select group_concat(name,'||') from phople group by sex; ## 默认链接为 ','; 这里可以改变链接符号。

          运行结果:

        zh||
        az||,aa||,ad||

    2. IFNULL方法

      MYSQL IFNULL(expr1,expr2)          
          如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2。IFNULL()返回一个数字或字符串值,取决于它被使用的上下文环境。          

    3. IF 方法

      IF(expr1,expr2,expr3)          
      如果expr1是TRUE(expr1<>0且expr1<>NULL),那么IF()返回expr2,否则它返回expr3。IF()返回一个数字或字符串值,取决于它被使用的上下文。          
      mysql> select IF(1>2,2,3);      
                 -> 3

    4. CONCAT(str1,str2,…)  字符串相连接的的函数。

        返回结果为连接参数产生的字符串。如有任何一个参数为NULL ,则返回值为 NULL。

    5. FIND_IN_SET(str, strlist);

      mysql> select find_in_set('b', 'a,b,c');

      >2

      返回 b在'a,b,c'字符串中的第几个。注意的是 'a,b,c' 这个字符串必须是要用 ',' 分隔。否则返回0,无效。

      

  • 相关阅读:
    前后端分离djangorestframework—— 在线视频平台接入第三方加密防盗录视频
    ORACLE ASMLIB
    1519484
    How to deploy Oracle 12c Release 2 Grid and RAC Database on RHEL 7.x
    2647673
    Installation of SAP on RAC with Oracle ASM(转)
    redhat7.2下VNC没法显示图像
    Oracle12C
    (转)linux 内存管理——内核的shmall 和shmmax 参数
    ora121 tips
  • 原文地址:https://www.cnblogs.com/shaoshao/p/5666142.html
Copyright © 2011-2022 走看看