sql - Records with a field that is a sum -


i trying create multiple items form in ms access each record has field aggregate value. is, have 2 tables 1 many relationship. each record in table (the 'one' in 1 many), sum field table b (the 'many' in 1 many).

i tried using record source inner join , sum sql statements not work because sum function returns single aggregate value (only 1 row sum of records). want 1 row each unique record in table , having field sums related records table b.

oh gosh. hope makes sense read it. explanation seems can confusing not sure how clarify more that.

sound simple:

select      a.field1, sum(b.field2) sumoffield2     [yourtablea]     inner join [yourtableb] b on a.id = b.idofa group      a.field1 

this should give 1 aggregate value every value of field1. replace field , table names suit needs.

tips:

  1. if need group more values, add them field list (the select part of instruction) and grouping fields (the group by part of instruction)
  2. if need show values of table don't have related record in table b, replace inner join left join (the sum zero)

hope helps


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -