Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 04-11-2007, 03:03 PM database addition
FutileSoul's Avatar
Ultra Talker

Posts: 383
Location: Michigan
Trades: 0
how would i go about taking two or more fields in a database table and adding them up?


example table - I want to add up scores and display the total in the total column

| NAME | SCORE 1 | SCORE 2 | SCORE 3 | TOTAL |
-------------------------------------------------
|--Bill--|---50----|---20----|----70----|---??---|
|-Dave-|---60----|---10----|----20----|---??---|
|-Josh--|---80----|---50----|----10----|---??---|
__________________

Please login or register to view this content. Registration is FREE
- The Congregation of Man

Last edited by FutileSoul; 04-11-2007 at 03:05 PM..
FutileSoul is offline
Reply With Quote
View Public Profile Visit FutileSoul's homepage!
 
 
Register now for full access!
Old 04-11-2007, 05:26 PM Re: database addition
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
you could just add them together of course

select fieldlist,field1 + field2 +fieldn as total from table
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-11-2007, 05:39 PM Re: database addition
FutileSoul's Avatar
Ultra Talker

Posts: 383
Location: Michigan
Trades: 0
so i wouldn't need a column named "total" in my database
__________________

Please login or register to view this content. Registration is FREE
- The Congregation of Man
FutileSoul is offline
Reply With Quote
View Public Profile Visit FutileSoul's homepage!
 
Old 04-11-2007, 05:55 PM Re: database addition
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Not for the addition you wouldn't
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-12-2007, 04:21 AM Re: database addition
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Databases are about a lot more than just storing data. Queries let you look at your data in new ways, and see things that you aren't storing directly. Averages, totals, top 10 lists, and so on.

You might want to create a "view" ( a query saved into the database ) with the formula for "total" though. If you decide to add a Score 4, Score 5, and so on, you could make the change in just one place if the rest of your site / app queries the view instead of the underlying table.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 04-12-2007, 09:16 AM Re: database addition
FutileSoul's Avatar
Ultra Talker

Posts: 383
Location: Michigan
Trades: 0
Quote:
Originally Posted by ForrestCroce View Post
Databases are about a lot more than just storing data. Queries let you look at your data in new ways, and see things that you aren't storing directly. Averages, totals, top 10 lists, and so on.

You might want to create a "view" ( a query saved into the database ) with the formula for "total" though. If you decide to add a Score 4, Score 5, and so on, you could make the change in just one place if the rest of your site / app queries the view instead of the underlying table.
this sounds like what i need, i will try to figure it out
from what i see if i add the scores up in the code itself i wouldn't be able to put the total scores in descending order, or would I??
__________________

Please login or register to view this content. Registration is FREE
- The Congregation of Man
FutileSoul is offline
Reply With Quote
View Public Profile Visit FutileSoul's homepage!
 
Old 04-12-2007, 09:28 AM Re: database addition
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You can order by an column alias ( column AS alias_name ) in exactly the same way as you can using a column name.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-12-2007, 10:04 AM Re: database addition
FutileSoul's Avatar
Ultra Talker

Posts: 383
Location: Michigan
Trades: 0
i figured out where to put the formulas, but can someone point me in the right direction as to what to put for the formulas, how the format of the formulas go
__________________

Please login or register to view this content. Registration is FREE
- The Congregation of Man
FutileSoul is offline
Reply With Quote
View Public Profile Visit FutileSoul's homepage!
 
Old 04-12-2007, 02:09 PM Re: database addition
Skilled Talker

Posts: 94
Trades: 0
Depending on how often how many records etc. It may be best for performance to actually create a row total.
__________________
Sell Templates? Try our
Please login or register to view this content. Registration is FREE
! See a live
Please login or register to view this content. Registration is FREE
ChadR is offline
Reply With Quote
View Public Profile
 
Old 04-13-2007, 03:04 AM Re: database addition
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by FutileSoul View Post
i figured out where to put the formulas, but can someone point me in the right direction as to what to put for the formulas, how the format of the formulas go
Which formulas have you worked out ?

A simple addition is as I put in post #2
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to database addition
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29743 seconds with 12 queries