SQL Is it possible to setup a column that will contain a value dependent on another column?

Posted by Wesley on Stack Overflow See other posts from Stack Overflow or by Wesley
Published on 2010-03-19T17:37:39Z Indexed on 2010/03/19 17:41 UTC
Read the original article Hit count: 331

Filed under:
|
|

I have a table (A) that lists all bundles created off a machine in a day. It lists the date created and the weight of the bundle. I have an ID column, a date column, and a weight column. I also have a table (B) that holds the details related to that machine for the day. In that table (B), I want a column that lists a sum of weights from the other table (A) that the dates match on. So if the machine runs 30 bundles in a day, I'll have 30 rows in table (A) all dated the same day. In table (B) I'll have 1 row detailing other information about the machine for the day plus the column that holds the total bundle weight created for the day.

Is there a way to make the total column in table (B) automatically adjust itself whenever a row is added to table (A)? Is this possible to do in the table schema itself rather than in an SQL statement each time a bundle is added? If it's not, what sort of SQL statement do I need?

Wes

© Stack Overflow or respective owner

Related posts about sql

Related posts about schema