Nested query microsoft access -
i have table of transactions. table multiple vendors multiple transactions multiple transaction amounts. need update table if vendors transaction more double transaction amount average vendor. far came following code wrong:
update tbltransaction set variabilityindicator = 1 transactionnumber in (select transactionnumber tbltransaction group vendorname having transactionamount >= avg(transactionamount*2))
the code above wrong. came statement possibly nested:
select avg(transactionamount) vendorname tbltransaction group vendorname
this should return vendornames average transaction amounts. how can nest can compare transactionamount average vendor names match??
update tbltransaction set variabilityindicator = 1 transactionnumber in ( select t.transactionnumber tbltransaction t t.transactonamount > 2 * ( select avg(transactionamount) tbltransaction a.vendorname = t.vendorname ) )
you may want check business logic exclude transactionamount being evaluated average calculation. may not want match on vendor name, on sort of id number/primary key value.
Comments
Post a Comment