FUDforum - خوراک RDF
http://fudforum.org/forum/index.php
Adding (Add - Subtract) values from two different tables to another table
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=182420&th=123124#msg_182420
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.]]>vikas daiya2013-08-04T03:54:29-00:00Re: Adding (Add - Subtract) values from two different tables to another table
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=182421&th=123124#msg_182421
> 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]]>Daniel Pitts2013-08-04T04:31:31-00:00Re: Adding (Add - Subtract) values from two different tables to another table
http://fudforum.org/forum/index.phpindex.php?t=rview&goto=182428&th=123124#msg_182428
> 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@attglobal.net
==================]]>Jerry Stuckle2013-08-04T13:47:30-00:00