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:
- if need group more values, add them field list (the
select
part of instruction) and grouping fields (thegroup by
part of instruction) - 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
Post a Comment