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?
You should give your calculations aliases.
7 2606
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.
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: - $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";
-
-
$y = $row['SUM(e.quantity_1)'];
-
$x = $row['SUM(o.quantity)'];
-
$z = $row['SUM(e.quantity_1)'] - $row['SUM(o.quantity)'];
-
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.
You should give your calculations aliases.
Hi Rabbit, it is means i should do the calculation something like this:
$z = $y - $x;
No, I mean that you should give your expressions in your SQL aliases. - select sum(someField) AS SumOfSomeField
Thanks, i just need to change code position. - $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";
-
$result = mysql_query($query) or die(mysql_error());
-
-
-
while($row = mysql_fetch_array($result)){
-
-
$y = $row['SUM(e.quantity_1)'];
-
$x = $row['SUM(o.quantity)'];
-
$z = ($row['SUM(e.quantity_1)'] - $row['SUM(o.quantity)']);
-
-
?>
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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 ...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |