SQL Server aggregate function sum computed as NULL, how to return 0

Source: Internet
Author: User

Usually we have several commonly used aggregate functions to calculate the data for a table in a database

1, Count: counting

2. Sum: Calculate sum

3, Avg: Averaging

4, Max: Take maximum value

5, min: Take the minimum value

6, IsNull: When the return data is empty, the default setting is 0

7, COALESCE: When the return data is empty, the default setting is 0

1. Use of Count

Here is all the data for a student table

1) Calculate the number of data in the table, COUNT (*), return the result of the knot is 6

2) The number of address data in the Count table, count (address), the return result is 5

2, the use of sum

1) Calculate the total age

3. Use of AVG

1) Calculate the average age in the table

4. Use of Max

1) Calculate maximum age

5, Min's use

1) Calculate minimum age

When the data for an aggregate function query is NULL, it is returned null

For example: Calculate the sum of the ages of id>9

6, the use of IsNull

1) Calculate sum, we want no data to return 0 instead of returning NULL

7, the use of coalesce

1) Calculate sum, we want no data to return 0 instead of returning NULL

SQL Server aggregate function sum computed as NULL, how to return 0

Related Article

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.