Page 1 of 1

Adding Values from mySQL

Posted: Wed Aug 18, 2004 12:19 pm
by traffic
Hello...

I have a large database called 'tracking'... I have thousands of rows with fields in them that include fields called 'need' and 'delivered'...

'need' and 'delivered' are tinyInt that have 1-2 digit numbers in them...

What I want to do is query the database and get the TOTAL number of the difference between 'need' and 'delivered'...

Let's say example of two rows:

need = '20'
delivered = '5'

(the difference would be '15')

need = '18'
delivered = '4'

(the difference would be '14')

So the query would spit out => '29' (the differences added together)


Thank you for any help you can give me...


...

Posted: Wed Aug 18, 2004 12:22 pm
by feyd
untested

Code: Select all

SELECT SUM( ABS( `need` - `delivered` ) ) `sum` FROM `table_name`

Posted: Wed Aug 18, 2004 12:49 pm
by traffic
Thank you...

Worked great...


...