ma****@gmail.com wrote:
As far as I know, SUM() works as mentioned below
The SUM function returns the sum of a set of numbers.
The argument values must be numbers (built-in types only) and their sum
must be within the range of the data type of the result.
The data type of the result is the same as the data type of the
argument values except that:
The result is a large integer if the argument values are small
integers.
The result is double-precision floating point if the argument values
are single-precision floating point.
This is an abstract from DB2 Information center
But how does SUM() take a literal value and multiply it with number of
rows in that table ....etc?
SUM doesn't multiply anything. It just takes 100 for each of the rows (7 in
your case) and sums those 100s up. Your query is logically the same like
this one:
SELECT SUM(col1), count(*)
FROM ( SELECT 100
FROM master_tab ) AS t(col1)
Whether you specify a column name as argument or a literal doesn't matter.
DB2 (and any other SQL engine) will take the value it finds in each row -
either a column value or the literal - and sum it up.
--
Knut Stolze
Information Integration
IBM Germany / University of Jena