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.

PHP Forum


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



Freelance Jobs

Reply
php sql help. adding rows together???
Old 03-01-2009, 12:00 AM php sql help. adding rows together???
Novice Talker

Posts: 14
Name: biklad
Trades: 0
Here is my situation:

Im trying to figure out how to add rows together to get "volume"

here an example of my table

id symbol shares volume price
13 JAME 100 100 50.00
14 JAME 50 "X" 50.00

what SQL query do i use to make the "x" in id 14 equal to the volume in 13 + shares in 14.

basically how do i have "X" replaced with 150
jcrensha627 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-01-2009, 02:25 AM Re: php sql help. adding rows together???
Novice Talker

Posts: 14
Name: biklad
Trades: 0
i do want the number to add up so i can have an idea of the volume of the shares. this needs to be updated so the price will fluctuate with it. Also im trying to figure how to make Y fluctuate based on "X"


id symbol shares volume price
13 JAME 100 100 50.00
14 JAME 50 "X" "Y"
15
16...
jcrensha627 is offline
Reply With Quote
View Public Profile
 
Old 03-01-2009, 06:37 PM Re: php sql help. adding rows together???
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
See if I have this right.

You want "volume" to be a running total of two values. Yes?

If so, it cannot be done in a single SQL query. SQL simply doesn't work like that.
At first looks I would say that you will need to write a stored procedure to perform a query that returned the required records, THEN have a routine to iterate through the returned rows and insert the running total into each row.
Certainly NOT something for an inexperienced DBA to be trying to accomplish

Your running total would be done simpler (and possibly quicker) when you are processing and displaying the returned records.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is 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 03-04-2009, 07:48 PM Re: php sql help. adding rows together???
Experienced Talker

Posts: 33
Trades: 0
it would be easier for you to do it in php looping through the result of a query and adding the volume to a variable so that the variable can then be output each time.
If it must be done in the SQL as chrishirst said you need a stored procedure which would act much the same.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
rambo3 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php sql help. adding rows together???
 

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.37153 seconds with 12 queries