group by - Access query: TOP 1 with TOTALS is doubling up my SUM -
when run simple query in ms access, single table, doubles sum column.
select top 1 data.item, reference.[proposed new category] type, sum(data.[qty sold]) [nbr sold] data inner join reference on data.item = reference.[item name] data.[month date] = [type 1st of month want - aug 2013, type 8/1/2013] group data.item, reference.[proposed new category] order sum(data.[qty sold]) desc;
yes, saw both of these, please don't muss thread referring them unless it's constructively explain why applicable. neither of them addressed situation (one self-join , other 1 joins - have no self joins).
cumulative totals being doubled
access 2010 doubling sum in query
why doubling inherent in query, , how can avoid it?? want top 1 item sum of qty sold descending...sounds simple. i'd avoid doing bunch of typical "access junk", make table queries etc., there way around it?
one thing cause if join many-to-many relation not one-to-many relation intended, in case inner join
return more intersection of 2 tables in weak sense of 'intersection'. fact joining on text field makes me doubly suspicious - presumably [item name]
isn't primary key of reference
? 1 way test hypothesis amend query force one-to-many relation:
select top 1 data.item, r2.[proposed new category] type, sum(data.[qty sold]) [nbr sold] data inner join ( select reference.[item name], first(reference.[proposed new category]) reference group reference.[item name]) r2 on d2.item = r2.[item name] (((d2.[month date])=[type 1st of month want - aug 2013, type 8/1/2013])) group d2.item, r2.[proposed new category] order sum(d2.[qty sold]) desc;
if comes expected value, need fix reference
remove duplicate entries. i'd recommend adding proper primary key, if there isn't 1 there ('item name' doesn't sound particularly primary key-ish, whereas 'itemcode' or 'itemid' would) , making relationship data
against that.
Comments
Post a Comment