Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub-total from an other table?

Status
Not open for further replies.

saturnius

Technical User
May 7, 2002
22
GB
Hello,
I have the following two tables with a column "sum" that should contain the sub-total as described. Thaks in advance!

table1: overview
column1:eek:verviewID
column2:name
column3:sum -> (of all rows of table2.overviewID - this field shoul contain the sum of all single scores for the particular overview ID and should change automatical when new details are added)

table2: details
column1:detailID
column2:eek:verviewID
column3:score (from 1-10)
 
Code:
select overview.overviewID
     , overview.name
     , sum(details.score)
  from overview
inner 
  join details
    on overview.overviewID = details.overviewID
group
    by overview.overviewID

do not save the sum in the overview table unless you have a good reason :)

rudy
 
Hello,
Thank you for your answer.
It is easier to have the value of the sum of all detail scores in the overview table then to calculate it always new. But I will change the sum when I add a new item to the details.
Thank you!
 
Saturnius,

It may seem easier to store that calculated field now, but the first time you find you've got bad data in there you'll wish you'd not done it. One of the biggest principles of database design is that you don't store calculated values unless you absolutely need them.

Jeremy =============
Jeremy Wallace
Designing and building Access databases since 1995.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top