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