MySQL Knowledge points

Source: Internet
Author: User

1.WITH ROLLUP: Statistical data is performed on a group basis.

Example: First grouping on the name field and then counting on a group basis

Mysql>SELECT Name,SUM(Singin) AsSingin_count from Employee_tbl GROUP by name with ROLLUP;+--------+--------------+|Name|Singin_count|+--------+--------------+| Xiaoli | 2 || Xiao ming | 7 ||   Xiao Wang  |7 ||  NULL | 16 |+--------+--------------+4 rows in set  ( 0.00 Sec) 

2.coalesce 
Select Coalesce(a,b,c);

Parameter description: If a==null, select B; If b==null, select C; If A!=null, select A; if a b c is null, the return is null (meaningless).

In the following example, if the name is empty, we use the total number instead:

Mysql>SELECT COALESCE(Name, Total),SUM(Singin) AsSingin_count from Employee_tbl GROUP by name with ROLLUP;+--------------------------+--------------+|Coalesce(Name, Total) |Singin_count|+--------------------------+--------------+| Xiaoli | 2 || Xiao ming | 7 | | Xiao Wang  |7 ||   Total  |16 |+--------------------------+--------------+4in set  (0.01 Sec) 

3.NULL value
(1) is null: This operator returns True when the value of the column is null.
(2) is not NULL: the operator returns True when the value of the column is not NULL.
    • (3) <=>: Comparison operators (unlike the = operator), which returns True when the two value of a comparison is NULL.
(4) The comparison of the null value to any other value (even null) returns False forever, that is, NULL = NULL returns FALSE.

              

MySQL Knowledge points

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.