FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Adding (Add - Subtract) values from two different tables to another table
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
Adding (Add - Subtract) values from two different tables to another table [message #182420] Sat, 03 August 2013 23:54 Go to next message
vikas daiya is currently offline  vikas daiya
Messages: 2
Registered: August 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
am developing inventory page in php with database as mentioned below. I have some complex equation which I am unable to resolve. Please help me out.

I have one table name "A" with column X and Y having values as follows:

Table "A"

------------
X Y
------------
blue 0
yellow 0
brown 0
Table "B" in following pattern.

------------
X Y
------------
blue 50
yellow 15
blue 20
brown 5
similarly Table "C"

------------
X Y
------------
blue 15
yellow 10
blue 5
brown 5
Now what I want if I add record in table "B" as mention above it should be updated in table "A" with following equation.

"A"= "B"-"C"

result should be i.e

Table "A"

------------
X Y
------------
blue 20
yellow 5
brown 0
same in case of adding in records table "C" equation should be as follows:

please note X values in table "A" are DISTINCT where as in other table are not.
Re: Adding (Add - Subtract) values from two different tables to another table [message #182421 is a reply to message #182420] Sun, 04 August 2013 00:31 Go to previous messageGo to next message
Daniel Pitts is currently offline  Daniel Pitts
Messages: 68
Registered: May 2012
Karma: 0
Member
add to buddy list
ignore all messages by this user
On 8/3/13 8:54 PM, vikas daiya wrote:
> am developing inventory page in php with database as mentioned below. I have some complex equation which I am unable to resolve. Please help me out.
>
> I have one table name "A" with column X and Y having values as follows:
>
> Table "A"
>
> ------------
> X Y
> ------------
> blue 0
> yellow 0
> brown 0
> Table "B" in following pattern.
>
> ------------
> X Y
> ------------
> blue 50
> yellow 15
> blue 20
> brown 5
> similarly Table "C"
>
> ------------
> X Y
> ------------
> blue 15
> yellow 10
> blue 5
> brown 5
> Now what I want if I add record in table "B" as mention above it should be updated in table "A" with following equation.
>
> "A"= "B"-"C"
>
> result should be i.e
>
> Table "A"
>
> ------------
> X Y
> ------------
> blue 20
> yellow 5
> brown 0
> same in case of adding in records table "C" equation should be as follows:
>
> please note X values in table "A" are DISTINCT where as in other table are not.
>
This sounds more like a SQL problem then PHP.

Try something along the lines:

select sum(B.y) - sum(C.y) from B, C on B.x=C.x group by B.x
Re: Adding (Add - Subtract) values from two different tables to another table [message #182428 is a reply to message #182421] Sun, 04 August 2013 09:47 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 8/4/2013 12:31 AM, Daniel Pitts wrote:
> On 8/3/13 8:54 PM, vikas daiya wrote:
>> am developing inventory page in php with database as mentioned
>> below. I have some complex equation which I am unable to resolve.
>> Please help me out.
>>
>> I have one table name "A" with column X and Y having values as follows:
>>
>> Table "A"
>>
>> ------------
>> X Y
>> ------------
>> blue 0
>> yellow 0
>> brown 0
>> Table "B" in following pattern.
>>
>> ------------
>> X Y
>> ------------
>> blue 50
>> yellow 15
>> blue 20
>> brown 5
>> similarly Table "C"
>>
>> ------------
>> X Y
>> ------------
>> blue 15
>> yellow 10
>> blue 5
>> brown 5
>> Now what I want if I add record in table "B" as mention above it
>> should be updated in table "A" with following equation.
>>
>> "A"= "B"-"C"
>>
>> result should be i.e
>>
>> Table "A"
>>
>> ------------
>> X Y
>> ------------
>> blue 20
>> yellow 5
>> brown 0
>> same in case of adding in records table "C" equation should be as
>> follows:
>>
>> please note X values in table "A" are DISTINCT where as in other table
>> are not.
>>
> This sounds more like a SQL problem then PHP.
>
> Try something along the lines:
>
> select sum(B.y) - sum(C.y) from B, C on B.x=C.x group by B.x

I agree - this is a database problem, and should be followed up in a
newsgroup related to the database (depending on which database he is
using, there may be multiple options).

However, the fact he needs to update table "a" when table "b" is updated
indicates a severe normalization problem.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: ini_get("memory_limit") returns an empty string
Next Topic: Hopiing for some leads as to what may be wrong in this code
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Oct 19 06:47:41 EDT 2017

Total time taken to generate the page: 0.00708 seconds