Use of aggregate functions

Source: Internet
Author: User

Aggregate functions in the statistics of a ~, are often common gray. But there's a little bit to be aware of.

Create Table#Tmp (AintBint )Insert  into#Tmp (A, B)Values(1,NULL),(NULL,NULL),(NULL,3),(2,4)Select *  from#Tmpa b----------- -----------1           NULLNULL        NULLNULL        32           4

Here I'll simply try using the count and Sum and AVG 3 most commonly used functions. This usage is very simple, just pay attention to the behavior of the null value in this area.

Select COUNT(*),COUNT(a),COUNT(A+b from#TmpSelect sum(a),sum(b),sum(A+b from#TmpSelect avg(a),avg(b*1.0),avg(A+b from#Tmp----------- ----------- -----------4           2           1                        ----------- ----------- -----------3           7           6                                                    ----------- --------------------------------------- -----------1           3.500000                                6

Note that when the row data contains a null value, the row data is filtered. COUNT (*) excepted

(*^__^*) hehe ...

Use of aggregate functions

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.