<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                [TOC] # 聚集函數 聚合函數對一組值執行計算并返回單一的值。聚合函數忽略空值。聚合函數經常與SELECT語句的GROUP BY子句一同使用。 所有聚合函數都具有確定性。任何時候用一組給定的輸入值調用它們時,都返回相同的值。 在OceanBase的聚合函數中,Value表達式只能出現一個。例如:不支持COUNT(c1, c2),僅支持COUNT(c1)。 ## AVG **聲明** `AVG(([DISTINCT] expr)` **說明** 返回指定組中的平均值,空值被忽略。DISTINCT選項可用于返回expr的不同值的平均值。若找不到匹配的行,則AVG()返回NULL。 **例子** ~~~ Oceanbase>select * from oceanbasetest; +----+------+------+ | id | ip | ip2 | +----+------+------+ | 1 | 4 | NULL | | 3 | 3 | NULL | | 4 | 3 | NULL | +----+------+------+ 3 rows in set (0.01 sec) Oceanbase>select avg(ip2), avg(ip), avg(distinct(ip)) from oceanbasetest; +----------+---------+-------------------+ | avg(ip2) | avg(ip) | avg(distinct(ip)) | +----------+---------+-------------------+ | NULL | 3.3333 | 3.5000 | +----------+---------+-------------------+ 1 row in set (0.00 sec) Oceanbase>select avg(distinct(ip)),avg(ip),avg(ip2) from oceanbasetest; +-------------------+---------+----------+ | avg(distinct(ip)) | avg(ip) | avg(ip2) | +-------------------+---------+----------+ | 3.5000 | 3.3333 | NULL | +-------------------+---------+----------+ 1 row in set (0.00 sec) ~~~ ## COUNT **聲明** `COUNT([DISTINCT] expr)` **說明** COUNT(\[DISTINCT\] expr )返回SELECT語句檢索到的行中非NULL值的數目。若找不到匹配的行,則COUNT()返回0。DISTINCT選項可用于返回 expr 的不同值的數目。 COUNT(\*)的稍微不同之處在于,它返回檢索行的數目,不論其是否包含NULL值。 **例子** ~~~ Oceanbase>select * from oceanbasetest; +----+------+------+ | id | ip | ip2 | +----+------+------+ | 1 | 4 | NULL | | 3 | 3 | NULL | | 4 | 3 | NULL | +----+------+------+ 3 rows in set (0.00 sec) Oceanbase>select count(ip2), count(ip), count(distinct(ip)), count(*) from oceanbasetest; +------------+-----------+---------------------+----------+ | count(ip2) | count(ip) | count(distinct(ip)) | count(*) | +------------+-----------+---------------------+----------+ | 0 | 3 | 2 | 3 | +------------+-----------+---------------------+----------+ 1 row in set (0.00 sec) ~~~ ## MAX **聲明** `MAX([DISTINCT] expr)` **說明** 返回指定數據中的最大值。 MAX()的取值可以是一個字符串參數;在這些情況下,它們返回最大字符串值。DISTINCT關鍵字可以被用來查找 expr的不同值的最大值,這產生的結果與省略DISTINCT 的結果相同。 假設表a有三行數據:id=1,num=10;id=2,num=20;id=3,num=30。 **例子** ~~~ Oceanbase>SELECT MAX(num) FROM a; +-----------------+ | MAX(num) | +-----------------+ | 30 | +-----------------+ 1 row in set (0.00 sec) ~~~ ## MIN **聲明** `MIN([DISTINCT] expr)` **說明** 返回指定數據中的最小值。 MIN()的取值可以是一個字符串參數;在這些情況下,它們返回最小字符串值。DISTINCT關鍵字可以被用來查找expr 的不同值的最小值,然而,這產生的結果與省略DISTINCT 的結果相同。 假設表a有三行數據:id=1,num=10;id=2,num=20;id=3,num=30。 **例子** ~~~ Oceanbase>SELECT MIN(num) FROM a; +----------------+ | MIN(num) | +----------------+ | 10 | +----------------+ 1 row in set (0.00 sec) ~~~ ## SUM **聲明** `SUM([DISTINCT] expr)` **說明** 返回 expr 的總數。若返回集合中無任何行,則 SUM() 返回NULL。DISTINCT關鍵字可用于求得 expr 不同值的總和。 若找不到匹配的行,則SUM()返回NULL。 **例子** ~~~ Oceanbase>select * from oceanbasetest; +------+------+------+ | id | ip | ip2 | +------+------+------+ | 1 | 4 | NULL | | 3 | 3 | NULL | | 4 | 3 | NULL | +------+------+------+ 3 rows in set (0.00 sec) Oceanbase>select sum(ip2),sum(ip),sum(distinct(ip)) from oceanbasetest; +----------+---------+-------------------+ | sum(ip2) | sum(ip) | sum(distinct(ip)) | +----------+---------+-------------------+ | NULL | 10 | 7 | +----------+---------+-------------------+ 1 row in set (0.00 sec) ~~~ ## GROUP\_CONCAT **聲明** `GROUP_CONCAT([DISTINCT] expr)` **說明** 該函數返回帶有來自一個組的連接的非NULL值的字符串結果。 ~~~ GROUP_CONCAT([DISTINCT] expr [,expr ...] [ORDER BY {unsigned_integer | col_name | expr} ASC | DESC] [SEPARATOR str_val]) ~~~ **例子** ~~~ Oceanbase>select * from book; //表book(書編號,書名,出版社) +--------+--------------------------------+-----------------------------+ | bookid | bookname | publishname | +--------+--------------------------------+-----------------------------+ | 1 | git help | alibaba group publisher | | 2 | MySQL性能優化 | 浙江大學圖文出版社 | | 3 | JAVA編程指南 | 機械工業出版社 | | 3 | JAVA編程指南 | 機械工業出版社 | | 4 | 大規模分布式存儲系統 | 機械工業出版社 | +--------+--------------------------------+-----------------------------+ 5 rows in set (0.00 sec) //查找書名信息 Oceanbase>select group_concat(bookname) from book group by bookname; +-----------------------------------+ | group_concat(bookname) | +-----------------------------------+ | git help | | JAVA編程指南,JAVA編程指南 | | MySQL性能優化 | | 大規模分布式存儲系統 | +-----------------------------------+ 4 rows in set (0.00 sec) //查找書名信息,書名唯一 Oceanbase>select group_concat(distinct(bookname)) from book group by bookname; +----------------------------------+ | group_concat(distinct(bookname)) | +----------------------------------+ | git help | | JAVA編程指南 | | MySQL性能優化 | | 大規模分布式存儲系統 | +----------------------------------+ 4 rows in set (0.01 sec) //查找書名和出版社信息,以書名分組,出版社信息降序排序顯示 Oceanbase>select bookname, group_concat(publishname order by publishname desc separator ';' ) from book group by bookname; +--------------------------------+---------------------------------------------------------------------+ | bookname | group_concat(publishname order by publishname desc separator ';' ) | +--------------------------------+---------------------------------------------------------------------+ | git help | alibaba group publisher | | JAVA編程指南 | 機械工業出版社;機械工業出版社 | | MySQL性能優化 | 浙江大學圖文出版社 | | 大規模分布式存儲系統 | 機械工業出版社 | +--------------------------------+---------------------------------------------------------------------+ 4 rows in set (0.00 sec) ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看