sql - Access UNION and JOIN query -
situation: access database i'm working on separates parts left , right parts. same part can used on both sides. trying create query count total number of individual parts needed per week.
question: how create query allows union multiple fields , join shown below?
table 1: part # |left part | left part qty | right part | right part quantity 1 xyz 5 lmn 7 2 abc 8 xyz 4 table 2: part # | needed 1 10 2 25 query: part | quantity xyz 150 (5 * 10) + (4 * 25) abc 200 (8 * 25) lmn 70 (7 * 10)
you have problem in ms access, because cannot put union
/union all
subquery. if have table of parts (which should have), can use left join
, think following want:
select p.partname, sum(nz(t1l.leftpartqty * t2.needed) + nz(t1r.rightpartqty * t2.needed)) ((part p inner join table2 t2 on p.part# - t2.part# ) left join table1 t1l on t1l.leftpart = p.partname ) left join table1 t1r on t1r.rightpart = p.partname group p.partname;
if don't have such table, can use view union all
, proceed there.
Comments
Post a Comment