473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

calculation that fetch value from different table

31
Hi,
Can i perform calculation that fetch value from different table in database?
i have two tables which are inbound and outbound table ,
i need to calculate item in stock,item out and total item.
i need to minus total item with item out,in order to find item in stock.
But the problem is total item is store in inbound table and item out is store in outbound table,
so how do i need to perform the calculation that fetch value from different table in database?
Dec 3 '12 #1

✓ answered by Rabbit

You should give your calculations aliases.

7 2606
Rabbit
12,516 Expert Mod 8TB
You can do that by joining the tables together. That's as much as I can say since I don't know anything about your table structures.
Dec 3 '12 #2
huda89
31
Hi Rabbit, thank you for your reply, I had done joining the table, but when I perform the calculation there's problem,I cannot get the value of $z, is there anything wrong with my code,thank you. Below is my code:

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT e.component_1, o.component_2, SUM(e.quantity_1), SUM(o.quantity) FROM equip_ments e LEFT JOIN outbound o ON e.serial_num=o.serial_num GROUP BY component_1";
  2.  
  3. $y = $row['SUM(e.quantity_1)'];
  4. $x = $row['SUM(o.quantity)'];
  5. $z = $row['SUM(e.quantity_1)'] - $row['SUM(o.quantity)'];
  6.  
Dec 5 '12 #3
zmbd
5,501 Expert Mod 4TB
We need to see the pertinent structure of the database and how the tables are related/joined .... something like:
TableName: tbl_example
[PK] autonumber primary key
[fieldone] Long foreign key to tbl_two 1:M
etc...

AND

Although one could assume that you're using MySQL as the database, it would be better if you would tell us which one you are using as there are some slight quirks between the various programs.
Dec 5 '12 #4
Rabbit
12,516 Expert Mod 8TB
You should give your calculations aliases.
Dec 5 '12 #5
huda89
31
Hi Rabbit, it is means i should do the calculation something like this:
$z = $y - $x;
Dec 6 '12 #6
Rabbit
12,516 Expert Mod 8TB
No, I mean that you should give your expressions in your SQL aliases.
Expand|Select|Wrap|Line Numbers
  1. select sum(someField) AS SumOfSomeField
Dec 6 '12 #7
huda89
31
Thanks, i just need to change code position.

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT e.component_1, o.component_2, SUM(e.quantity_1), SUM(o.quantity) FROM equip_ments e LEFT JOIN outbound o ON e.serial_num=o.serial_num GROUP BY component_1";
  2.     $result = mysql_query($query) or die(mysql_error());
  3.  
  4.  
  5. while($row = mysql_fetch_array($result)){
  6.  
  7. $y = $row['SUM(e.quantity_1)'];
  8. $x = $row['SUM(o.quantity)'];
  9. $z = ($row['SUM(e.quantity_1)'] - $row['SUM(o.quantity)']);
  10.  
  11. ?>
  12.  
Dec 6 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Will | last post by:
Hi, I have a form which calculates a final cost (frmWorkCosts, data stored in tblWorkCosts) and once calculated adds this final cost (Which isn't saved in tblWorkCosts) into a different table...
1
by: Martin | last post by:
Dear Group Sorry for bothering you again but I need expert advice on this. I have placed a HTML textbox on my aspx form and converted it to run as a server control. At some point in my code I...
5
by: sensreview | last post by:
Hello, I need help in selecting a value from combo list thru one lookup table and update different table on MS access form. For eg; I have a lookup table of usernames, I need to use this...
2
by: Prashantsd | last post by:
Hi, I just wanted to know if it is possible to save the form data into different table. The combox box list are from the different tables and want save in another new table. What are the...
2
by: robin1983 | last post by:
HI, I have a problem with sql query.. Actually, i have three different table eg. table1, table2, and table3. All the three table have same field name. Actually, my problem is that, whenever I insert...
2
by: freddy windey | last post by:
Hi, this my 1st time i join discussion. im just a new programmer. i need help from your expert on this "Insert data using 1 form to 2 different table"- ASP VBscript. example- name: age: DOB:...
4
by: billa856 | last post by:
Hi, I want to know how can we set the value of Textbox = value of field in table when we select a value form combobx. example i have a table customer CID CNAME CSALARY 1 Billa ...
1
by: rahullko05 | last post by:
Hi, i am building a small forum site as my final year project & stuck in a very trivial problem. I have a table which are varchar type of data & i am trying to fetch data from table based on...
1
by: markroworth | last post by:
Hi there, I am trying to understand under what circumstances there would be in using a different table owner other than dbo. My DBA has (it seems arbitrariry) to use different table owners with no...
12
by: CindySue | last post by:
I would like to be able to copy the current record to a different table. I am tracking donations and I create a new table of donations each year--some of the records will be the same or slightly...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.