...

View Full Version : sum(number)



BubikolRamios
03-02-2013, 01:16 PM
select sum(111) = 111


now try:



select sum(111) from xtable
select sum(111) from ytable

any you get some looks like randome numbers.

Any explanation ?

Arcticwarrio
03-05-2013, 10:54 PM
what is xtable ?

BubikolRamios
03-05-2013, 11:41 PM
it is any table.

Arcticwarrio
03-06-2013, 12:07 AM
its the number of entrys 3 times eg if you have 51 rows it will output 515151

Arcticwarrio
03-06-2013, 12:10 AM
or not, 4 rows = 444

31 rows = 3441

so its 111 * rows

Old Pedant
03-06-2013, 12:32 AM
Correct. 55 rows would be 5661.

It's easy to see this, Bubikol, if you do

SELECT COUNT(*), SUM(111) FROM xtable

What you are telling SQL (any SQL, not just MySQL) to do is to add 111 to the sum for each row in the table.

Think about it: If you do


SELECT SUM(someField) FROM xtable
all that tells SQL to do is to add the value of field someField to the sum for each row in the table. So when you use a constant, instead, it is the constant that gets added for each row.

Nothing "random" about it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum