3 Replies - 139 Views - Last Post: 08 May 2019 - 07:21 AM

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 634
  • View blog
  • Posts: 4,209
  • Joined: 12-January 10

how to calculate math from one table to another -----

Posted 07 May 2019 - 06:00 AM

ok i know the topic is a bit weird but here is the question in its entirety.: how would i be able to calculate the difference between information stored in different tables -- the kicker is that each table has multiple values..

example

table a                        table b                    table c
10000 pounds prd 1            prd 1 hour 1               shift 1 1200 hr 1 prd 2
230000 pounds prd 2           prd 1 hour 2                shift 1 10 hr 2 prd 1
                              prd 2 hour 1                shift 1 100 hr 3 prd 2
                                                            shift 2 100 hr 3 prd 2                     


i would need to subtract 230000 from table c where prd = 2 and shift 1 and subtract 10000 from table c where prd= 1 and shift 1 but the kicker is this needs to happen to each hour so in an 8 hour day i would need 10000 times which ever hour in the day it is by using table c entry and subtract table c amount for that hour and product from the running increment from table a


example:

10000 x 2 for 2 hours in the day for product 2 would be
20000 - 1300 for the 2 hours this is in the table

Is This A Good Question/Topic? 0
  • +

Replies To: how to calculate math from one table to another -----

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6819
  • View blog
  • Posts: 28,255
  • Joined: 12-December 12

Re: how to calculate math from one table to another -----

Posted 07 May 2019 - 06:24 AM

Use a JOIN to connect two tables via a common field.
Was This Post Helpful? 0
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 634
  • View blog
  • Posts: 4,209
  • Joined: 12-January 10

Re: how to calculate math from one table to another -----

Posted 07 May 2019 - 07:56 AM

yeah i tried that-- there are just to many possibilities from one table to another...

oh well im scrapping that for now since someone decided to move my may 31 deadline to may 9...
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2957
  • View blog
  • Posts: 11,484
  • Joined: 03-December 12

Re: how to calculate math from one table to another -----

Posted 08 May 2019 - 07:21 AM

Would need more of the table structure, but you want a join. You just need to know the clause to reduce those possibilities. The example you gave leaves too many gaps.


And with the join, you could do a view, or a stored procedure that does whatever, in steps, making it easier. It just depends what beliefs the organization has on how the database should be used.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1