github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/function/func_string_concat_ws.test (about)

     1  #SELECT, 嵌套
     2  DROP TABLE IF EXISTS t1;
     3  CREATE TABLE t1 ( number INT NOT NULL, alpha CHAR(6) NOT NULL );
     4  INSERT INTO t1 VALUES (1413006,'idlfmv'),
     5  (1413065,'smpsfz'),(1413127,'sljrhx'),(1413304,'qerfnd');
     6  
     7  SELECT number, any_value(alpha), CONCAT_WS('<---->',number,any_value(alpha)) AS new
     8  FROM t1 GROUP BY number;
     9  SELECT CONCAT_WS('<---->',number,alpha) AS new
    10  FROM t1 GROUP BY CONCAT_WS('<---->',number,alpha) LIMIT 1;
    11  
    12  SELECT any_value(number), any_value(alpha), CONCAT_WS('<->',any_value(number),any_value(alpha)) AS new
    13  FROM t1 GROUP BY new LIMIT 1;
    14  SELECT any_value(number), any_value(alpha), CONCAT_WS('-',any_value(number),any_value(alpha),any_value(alpha),any_value(alpha),any_value(alpha),any_value(alpha),any_value(alpha),any_value(alpha)) AS new
    15  FROM t1 GROUP BY new LIMIT 1;
    16  SELECT any_value(number), any_value(alpha), CONCAT_WS('<------------------>',any_value(number),any_value(alpha))
    17  FROM t1 GROUP BY CONCAT_WS('<------------------>',any_value(number),any_value(alpha)) LIMIT 1;
    18  drop table t1;
    19  
    20  #SELECT, 嵌套,NULL
    21  select concat_ws(', ','monty','was here','again');
    22  select concat_ws(',','',NULL,'a');
    23  -- @separator:table
    24  SELECT CONCAT_WS('"',CONCAT_WS('";"',space(60),space(60),space(60),space(100)), '"');
    25  
    26  
    27  #WHERE 
    28  CREATE TABLE t1(id int(11) NOT NULL,pc int(11) NOT NULL default 0,title varchar(20) default NULL,PRIMARY KEY (id));
    29  INSERT INTO t1 VALUES(1, 0, 'Main'),(2, 1, 'Toys'),(3, 1, 'Games');
    30  SELECT t1.id, CONCAT_WS('->', t3.title, t2.title, t1.title) as col1 FROM t1 LEFT JOIN t1 AS t2 ON t1.pc=t2.id LEFT JOIN t1 AS t3 ON t2.pc=t3.id;
    31  SELECT t1.id, CONCAT_WS('->', t3.title, t2.title, t1.title) as col1 FROM t1 LEFT JOIN t1 AS t2 ON t1.pc=t2.id LEFT JOIN t1 AS t3 ON t2.pc=t3.id WHERE CONCAT_WS('->', t3.title, t2.title, t1.title) LIKE '%Toys%';
    32  DROP TABLE t1;
    33  
    34  #WHERE
    35  CREATE TABLE t1(trackid     int(10) unsigned NOT NULL,trackname   varchar(100) NOT NULL default '',PRIMARY KEY (trackid));
    36  CREATE TABLE t2(artistid    int(10) unsigned NOT NULL,artistname  varchar(100) NOT NULL default '',PRIMARY KEY (artistid));
    37  CREATE TABLE t3(trackid     int(10) unsigned NOT NULL,artistid    int(10) unsigned NOT NULL,PRIMARY KEY (trackid));
    38  INSERT INTO t1 VALUES (1, 'April In Paris'), (2, 'Autumn In New York');
    39  INSERT INTO t2 VALUES (1, 'Vernon Duke');
    40  INSERT INTO t3 VALUES (1,1);
    41  SELECT CONCAT_WS(' ', trackname, artistname) trackname, artistname FROM t1 LEFT JOIN t3 ON t1.trackid=t3.trackid LEFT JOIN t2 ON t2.artistid=t3.artistid WHERE CONCAT_WS(' ', trackname, artistname) LIKE '%In%';
    42  drop table t1;
    43  drop table t2;
    44  drop table t3;
    45  
    46  
    47  
    48  #子查询
    49  CREATE TABLE t1 (f2 VARCHAR(20));
    50  CREATE TABLE t2 (f2 VARCHAR(20));
    51  INSERT INTO t1 VALUES ('MIN'),('MAX');
    52  INSERT INTO t2 VALUES ('LOAD');
    53  SELECT CONCAT_WS('_', (SELECT t2.f2 FROM t2), t1.f2) AS concat_name FROM t1;
    54  drop table t1;
    55  drop table t2;
    56  
    57  #嵌套
    58  
    59  create table t1 (a int, b int);
    60  insert into t1 values (1, 4),(10, 40),(1, 4),(10, 43),(1, 4),(10, 41),(1, 4),(10, 43),(1, 4);
    61  select a, MAX(b), CONCAT_WS(MAX(b), '43', '4', '5') from t1 group by a;
    62  drop table t1;
    63  
    64  
    65  
    66  #INSERT, DISTINCT
    67  #0.5 MO不支持CREATE TABLE SELECT写法
    68  #CREATE TABLE t1 (a MEDIUMINT NULL);
    69  #INSERT INTO t1 VALUES (1234567);
    70  #CREATE TABLE t2 AS SELECT CONCAT_WS(1,2,3) FROM t1;
    71  #INSERT INTO t2 VALUES(CONCAT_WS(2,3,4)),(CONCAT_WS(2,3,4)), (CONCAT_WS(5,6,7));
    72  #SELECT DISTINCT * from t2;
    73  #DROP TABLE t1;
    74  #DROP TABLE t2;
    75  
    76  
    77  #WHERE, EXTREME VALUES,嵌套
    78  #SET timestamp=UNIX_TIMESTAMP('2011-07-31 10:00:00');
    79  CREATE TABLE t1 (
    80  col_datetime_2_not_null_key datetime(2) NOT NULL,
    81  col_datetime_5 datetime(5) DEFAULT NULL,
    82  pk datetime(5) NOT NULL,
    83  PRIMARY KEY (pk));
    84  INSERT INTO t1 VALUES
    85  ('2001-10-20 00:00:00.00','2001-09-20 11:18:18.03630','2011-07-19 17:37:06.26725'),
    86  ('0001-01-01 00:00:00.00','0001-01-01 00:00:00.00000','2011-07-19 17:37:07.26725'),
    87  ('0001-01-01 00:00:00.00','0001-01-01 00:00:00.00000','2011-07-19 17:37:08.26725'),
    88  ('2000-01-14 17:55:57.03','0001-01-01 00:00:00.00000','2011-07-19 17:37:09.26725'),
    89  ('2006-12-27 07:25:14.04',NULL,'2011-07-19 17:37:10.26725'),
    90  ('2000-10-17 22:03:12.01','0001-01-01 00:00:00.00000','2011-07-19 17:37:11.26725'),
    91  ('0001-01-01 00:00:00.00','0001-01-01 00:00:00.00000','2011-07-19 17:37:12.26725'),
    92  ('0001-01-01 00:00:00.00','0001-01-01 00:00:00.00000','2011-07-19 17:37:13.26725'),
    93  ('0001-01-01 00:00:00.00','2008-06-04 23:05:50.03642','2011-07-19 17:37:14.26725'),
    94  ('2000-10-22 23:52:09.01',NULL,'2011-07-19 17:37:15.26725');
    95  SELECT col_datetime_2_not_null_key AS c1, col_datetime_5 AS c2
    96  FROM t1
    97  WHERE
    98  pk <> CONCAT_WS( ':','%I','%m' )+CONCAT_WS('-','%y','%H','%V','%k','%k' )
    99  OR
   100  year(col_datetime_5) < year(utc_timestamp())
   101  ORDER BY 1;
   102  DROP TABLE t1;
   103  #SET timestamp=DEFAULT;
   104  
   105  #EXTREME VALUES, 多语言
   106  
   107  SELECT CONCAT_WS(1471290948102948112341241204312904-23412412-4141, "a", "b");
   108  
   109  SELECT CONCAT_WS("147129094810294812983120", "@^%#&*@^$@(*&#()!@*", "a", "b");
   110  SELECT CONCAT_WS("123", "你好", "français", "にほんご");
   111  
   112  #DATA TYPES
   113  
   114  SELECT CONCAT_WS(1, 0.213, 213.4131, "abc", "2012-03-21 03:03:02", NULL);
   115  
   116  
   117  
   118  #ON CONDITION, HAVING, 比较操作
   119  create table t1(a INT,  b date);
   120  create table t2(a INT,  b date);
   121  insert into t1 values(1, "2012-10-12"),(2, "2004-04-24"),(3, "2008-12-04"),(4, "2012-03-23");
   122  insert into t2 values(1, "2012-10-12"),(2, "1994-10-04"),(3, "2018-06-04"),(4, "2012-10-12");
   123  SELECT t1.a,t1.b, t2.a,t2.b FROM t1 JOIN t2 ON (concat_ws(t1.a, t1.b) = concat_ws(t2.a, t2.b)) HAVING substring(concat_ws(t1.a, t1.b),1,1)='2';
   124  drop table t1;
   125  drop table t2;
   126  
   127