Add a SELECT field to the sum Operation--nullif, IsNull, NVL function of the use of the ___ function

Source: Internet
Author: User

In the spelling of the SQL statement to do a select out of the field to sum the query, search the Internet, get some inspiration, here to write. Let's begin by introducing the function you use:

1, Nullif (ORACLE and SQL Server use the same):

Usage:

Nullif (expression1 , expression2),

Description:

If two expressions are not equal, NULLIF returns the value of the first expression1.

If two expressions are equal, NULLIF returns a null value of--null.

2, ISUNLL (only for SQL server,oracle without this function)

Usage:

ISNULL (Check_expression,replacement_value)

Description:

Check_expression: An expression that will be checked for null. Check_expression can be of any type.

Replacement_value: An expression to be returned when check_expression is null.

Note:Replacement_value must have the same type as check_expresssion.

3, NVL (only applicable to Oracle,sql server does not have this function)

Usage:

NVL (Check_expression,replacement_value)

Description:

If check_expression is null, the NVL function returns the Replacement_value value, otherwise the Check_expression value is returned, or null if two arguments are null.

Note: Check_expression and Replacement_value must be of the same data type unless you explicitly use the To_char function for type conversion.

Example:

Sum the values of the Grade1_ and grade2_ two fields in the student table:

SQL Server statement:

Select IsNull (IsNull (s.grade1_,0) +isnull (R. grade2_,0), 0) fromstudent s

Oracle Statements:

Select NVL (NVL (s.grade1_,0) +NVL (R. grade2_,0), 0) from student s

Reference URL: http://blog.sina.com.cn/s/blog_622c401d0100tz29.html

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.