Adding Values from mySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
traffic
Forum Newbie
Posts: 17
Joined: Fri May 23, 2003 1:18 pm

Adding Values from mySQL

Post 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...


...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

untested

Code: Select all

SELECT SUM( ABS( `need` - `delivered` ) ) `sum` FROM `table_name`
traffic
Forum Newbie
Posts: 17
Joined: Fri May 23, 2003 1:18 pm

Post by traffic »

Thank you...

Worked great...


...
Post Reply