MySQL知識點

來源:互聯網
上載者:User

標籤:資料   set   rollup   小明   class   imp   比較   font   from   

1.WITH ROLLUP:在分組的基礎上進行統計資料。

例子:首先在name欄位上進行分組,然後在分組的基礎上進行統計

mysql> SELECT name, SUM(singin) as singin_count FROM  employee_tbl GROUP BY name WITH ROLLUP;+--------+--------------+| name   | singin_count |+--------+--------------+| 小麗 |            2 || 小明 |            7 || 小王 |            7 || NULL |           16 |+--------+--------------+4 rows in set (0.00 sec)

2.coalesce 
select coalesce(a,b,c);

參數說明:如果a==null,則選擇b;如果b==null,則選擇c;如果a!=null,則選擇a;如果a b c 都為null ,則返回為null(沒意義)。

以下執行個體中如果名字為空白我們使用總數代替:

mysql> SELECT coalesce(name, ‘總數‘), SUM(singin) as singin_count FROM  employee_tbl GROUP BY name WITH ROLLUP;+--------------------------+--------------+| coalesce(name, ‘總數‘) | singin_count |+--------------------------+--------------+| 小麗                   |            2 || 小明                   |            7 || 小王                   |            7 || 總數                   |           16 |+--------------------------+--------------+4 rows in set (0.01 sec)

3.NULL值
(1)IS NULL: 當列的值是 NULL,此運算子返回 true。
(2)IS NOT NULL: 當列的值不為 NULL, 運算子返回 true。
  • (3)<=>: 比較操作符(不同於=運算子),當比較的的兩個值為 NULL 時返回 true。
(4)NULL 值與任何其它值的比較(即使是 NULL)永遠返回 false,即 NULL = NULL 返回false 。

 


 

MySQL知識點

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.