View Full Version : sum(number)
03-02-2013, 01:16 PM
select sum(111) = 111
select sum(111) from xtable
select sum(111) from ytable
any you get some looks like randome numbers.
Any explanation ?
03-05-2013, 10:54 PM
what is xtable ?
03-05-2013, 11:41 PM
it is any table.
03-06-2013, 12:07 AM
its the number of entrys 3 times eg if you have 51 rows it will output 515151
03-06-2013, 12:10 AM
or not, 4 rows = 444
31 rows = 3441
so its 111 * rows
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.