Possible to ADD the total number of 3.5 million rows?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Possible to ADD the total number of 3.5 million rows?

Post by Deseree »

one mysql db, one mysql table, 3.5 million rows of data, is it possible to add the entire column "used" WITHOUT LOOPING!!! lol, i don't want to transverse 3.5 million rows of data, so is there a mysql command to add all the 1's and 0's in the 'used' column quickly, efficiently, without overkill of mysql proccesses? lol.....

I know i'm asking for alot this christmas, but i've been a really good boy this year!!!!

lol...
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post by Deseree »

looking into SUM() right now, hope this works...

Code: Select all

SUM(SELECT `used` FROM `table` WHERE `used` > 0)

COUNT(SELECT `used` FROM `table` WHERE `used` > 0)
Didn't work, any ideas?
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post by Deseree »

SELECT SUM(`used`) FROM `table` WHERE `used`=1
Answered my own question :)

IT CAN BE DONE!!! Not sure if it's the most efficient way, but it works!
Post Reply