0
点赞
收藏
分享

微信扫一扫

解决方案:2024年Pytorch(GPU版本)+ torchvision手动安装教程[万能安装方法] win64、linux、macos、arm、aarch64均适用

 🐓 序言

StarRocks新一代极速全场景 MPP (Massively Parallel Processing) 数据库StarRocks 的愿景是能够让用户的数据分析变得更加简单和敏捷。用户无需经过复杂的预处理,可以用StarRocks 来支持多种数据分析场景的极速分析。

 🐓 语法区别

字符串操作函数(String Functions)

CONCAT_WS

示例

CONCAT()

将多个字符串连接起来。如果参数中任意一个值是 NULL,那么返回的结果为 NULL。

MySQL > select concat("a", "b");
+------------------+
| concat('a', 'b') |
+------------------+
| ab               |
+------------------+

MySQL > select concat("a", "b", "c");
+-----------------------+
| concat('a', 'b', 'c') |
+-----------------------+
| abc                   |
+-----------------------+

MySQL > select concat("a", null, "c");
+------------------------+
| concat('a', NULL, 'c') |
+------------------------+
| NULL                   |
+------------------------+

SUBSTRING_INDEX()

示例:

Substring_Index()

-- 从左往右数截取第二个 `.` 分隔符前面的字符串。
mysql> select substring_index('https://www.starrocks.io', '.', 2);
+-----------------------------------------------------+
| substring_index('https://www.starrocks.io', '.', 2) |
+-----------------------------------------------------+
| https://www.starrocks                               |
+-----------------------------------------------------+

-- Count 为负,从右往左数截取第二个 `.` 分隔符之后的字符串,
mysql> select substring_index('https://www.starrocks.io', '.', -2);
+------------------------------------------------------+
| substring_index('https://www.starrocks.io', '.', -2) |
+------------------------------------------------------+
| starrocks.io                                         |
+------------------------------------------------------+

mysql> select substring_index("hello world", " ", 1);
+----------------------------------------+
| substring_index("hello world", " ", 1) |
+----------------------------------------+
| hello                                  |
+----------------------------------------+

mysql> select substring_index("hello world", " ", -1);
+-----------------------------------------+
| substring_index('hello world', ' ', -1) |
+-----------------------------------------+
| world                                   |
+-----------------------------------------+

-- Count 为 0,返回 NULL。
mysql> select substring_index("hello world", " ", 0);
+----------------------------------------+
| substring_index('hello world', ' ', 0) |
+----------------------------------------+
| NULL                                   |
+----------------------------------------+

-- Count 大于 `delimiter` 实际出现的次数,返回整个字符串。
mysql> select substring_index("hello world", " ", 2);
+----------------------------------------+
| substring_index("hello world", " ", 2) |
+----------------------------------------+
| hello world                            |
+----------------------------------------+

-- Count 大于 `delimiter` 实际出现的次数,返回整个字符串。
mysql> select substring_index("hello world", " ", -2);
+-----------------------------------------+
| substring_index("hello world", " ", -2) |
+-----------------------------------------+
| hello world                             |
+-----------------------------------------+

LENGTH()

 示例:

LENGTH()

MySQL > select length("abc");
+---------------+
| length('abc') |
+---------------+
|             3 |
+---------------+

MySQL > select length("中国");
+------------------+
| length('中国')   |
+------------------+
|                6 |
+------------------+

时间日期处理函数(Date and Time Functions)

YEARWEEK()

示例 :

DATE_FORMAT()

select date_format('2009-10-04 22:23:00', '%W %M %Y');
+------------------------------------------------+
| date_format('2009-10-04 22:23:00', '%W %M %Y') |
+------------------------------------------------+
| Sunday October 2009                            |
+------------------------------------------------+

select date_format('2007-10-04 22:23:00', '%H:%i:%s');
+------------------------------------------------+
| date_format('2007-10-04 22:23:00', '%H:%i:%s') |
+------------------------------------------------+
| 22:23:00                                       |
+------------------------------------------------+

select date_format('1900-10-04 22:23:00', '%D %y %a %d %m %b %j');
+------------------------------------------------------------+
| date_format('1900-10-04 22:23:00', '%D %y %a %d %m %b %j') |
+------------------------------------------------------------+
| 4th 00 Thu 04 10 Oct 277                                   |
+------------------------------------------------------------+

select date_format('1997-10-04 22:23:00', '%H %k %I %r %T %S %w');
+------------------------------------------------------------+
| date_format('1997-10-04 22:23:00', '%H %k %I %r %T %S %w') |
+------------------------------------------------------------+
| 22 22 10 10:23:00 PM 22:23:00 00 6                         |
+------------------------------------------------------------+

select date_format('1999-01-01 00:00:00', '%X %V');
+---------------------------------------------+
| date_format('1999-01-01 00:00:00', '%X %V') |
+---------------------------------------------+
| 1998 52                                     |
+---------------------------------------------+

select date_format('2006-06-01', '%d');
+------------------------------------------+
| date_format('2006-06-01 00:00:00', '%d') |
+------------------------------------------+
| 01                                       |
+------------------------------------------+

select date_format('2006-06-01', '%%%d');
+--------------------------------------------+
| date_format('2006-06-01 00:00:00', '%%%d') |
+--------------------------------------------+
| %01                                        |
+--------------------------------------------+

聚合函数(Aggregate Functions) 

COUNT(DISTINCT)

SUM() 和 AVG()        

示例:

SUM()

1.创建表

CREATE TABLE IF NOT EXISTS employees (
    region_num    TINYINT        COMMENT "range [-128, 127]",
    id            BIGINT         COMMENT "range [-2^63 + 1 ~ 2^63 - 1]",
    hobby         STRING         NOT NULL COMMENT "upper limit value 65533 bytes",
    income        DOUBLE         COMMENT "8 bytes",
    sales       DECIMAL(12,4)  COMMENT ""
    )
    DISTRIBUTED BY HASH(region_num);

2.插入数据 

INSERT INTO employees VALUES
(3,432175,'3',25600,1250.23),
(4,567832,'3',37932,2564.33),
(3,777326,'2',null,1932.99),
(5,342611,'6',43727,45235.1),
(2,403882,'4',36789,52872.4);

3.求和

MySQL > SELECT region_num, sum(sales) from employees
group by region_num;

+------------+------------+
| region_num | sum(sales) |
+------------+------------+
|          2 | 52872.4000 |
|          5 | 45235.1000 |
|          4 |  2564.3300 |
|          3 |  3183.2200 |
+------------+------------+
4 rows in set (0.01 sec)

GROUP_CONCAT()

GROUP BY ()

举报

相关推荐

0 条评论