473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

What does this mean?

Hi I m using DB2 8.2 on win XP

I am surprised to see the functioning of SUM() function

db2 => select sum(100),count(*) from sysibm.sysdummy1

1 2
----------- -----------
100 1

1 record(s) selected.
Can someone tell me the cause of such behaviour?
Thanks in advance
mailar

Nov 12 '05 #1
6 4081
<ma****@gmail.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
Hi I m using DB2 8.2 on win XP

I am surprised to see the functioning of SUM() function

db2 => select sum(100),count(*) from sysibm.sysdummy1

1 2
----------- -----------
100 1

1 record(s) selected.
Can someone tell me the cause of such behaviour?
Thanks in advance
mailar

There is one row in sysibm.sysdummy1 (this accounts for the count(*))

Taking the sum of a literal will equal the literal.

What is the question?
Nov 12 '05 #2
I am surprised to see this kind of behaviour of SUM() function

My master_tab table has 7 records

db2 => select sum(100),count(*) from master_tab

1 2
----------- -----------
700 7

1 record(s) selected.
So, can someone tell me how does the SUM() function actualy work?

Nov 12 '05 #3
ma****@gmail.com wrote:
So, can someone tell me how does the SUM() function actualy work?


It works exactly as it's expected to: it sums the given argument over
the grouped rows. 100 * 7 = 700 (afair, at least ;) )

Where's the problem? What did you expect as the result of your queries?
--
Please compose your messages as plaintext:
http://www.netby.dk/Oest/Europa-Alle/vermeer/plain.html
And do not send MS Office attachments:
http://www.goldmark.org/netrants/no-word/attach.html
Nov 12 '05 #4
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?

Nov 12 '05 #5
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?


I think you're assuming that Sum() works as it does in a spreadsheet...

Sum(1) = 1
Sum(1, 2) = 3
Sum(1, 2, 3) = 6

In a database aggregate functions work against *rows*. If the query uses a
Group By clause then the aggregations are over the rows "per group". If there
is no Group By clause then the aggregations are over the entire Result Set.
Nov 12 '05 #6
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
Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: Jukka K. Korpela | last post by:
I have noticed that the meaning of visibility: collapse has been discussed on different forums, but with no consensus on what it really means. Besides, implementations differ. The specification...
86
by: Michael Kalina | last post by:
Because when I asked for comments on my site-design (Remember? My site, your opinion!) some of you told me never to change anything on font-sizes! What do you guys think of that:...
44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
2
by: Steve Richter | last post by:
What does the "." mean in the following sql script stmts? use GO if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id,N'IsUserTable') = 1) drop table ....
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
1
by: Frank Rizzo | last post by:
Some of the classes in the framework are marked as thread-safe in the documentation. In particular the docs say the following: "Any public static (*Shared* in Visual Basic) members of this type...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
9
by: JoeC | last post by:
m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth; m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight; What does this mean? I have seen v=&var->member.thing; but what does it mean when you...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.