I've been racking my brains all day over this. And I'm not the best
at SQL either.
I need a query that will produce the following results:
Product,Warehou se,Sold_LastYea r,Sold_ThisYear ,Sold_3Months,S old_MTD
I've got four queries to give me the Sold_* fields. Their fields are
Product, Warehouse, and Units. I also have a table which these
queries originated from. The table UV_SPPROD (I didn't name it) has
Product, Warehouse, Period (aka date), and Units. Basically, the four
queries remove the date and give me the unit sum for a given date
range. Those queries all work fine.
My trouble is that when trying to pull in all the data, I can't seem
to match the product and warehouses for the four queries together to
get me a combined output. Just to make things more difficult, not all
periods are listed for each product/warehouse combination meaning that
I cannot simply join all product fields and all warehouse fields
together. I may "lose" data. At least that's what my tests showed.
I've tried using the base table UV_SPPROD to perform a left join but
seem to get cartesian joins with the data or lost data. I've also
tried a union with zeros as placeholders. That will work if I create
a final query to sum based on product and warehouse. I'm hoping to
create one query that will write the information.
Any help is appreciated.
-Chris
at SQL either.
I need a query that will produce the following results:
Product,Warehou se,Sold_LastYea r,Sold_ThisYear ,Sold_3Months,S old_MTD
I've got four queries to give me the Sold_* fields. Their fields are
Product, Warehouse, and Units. I also have a table which these
queries originated from. The table UV_SPPROD (I didn't name it) has
Product, Warehouse, Period (aka date), and Units. Basically, the four
queries remove the date and give me the unit sum for a given date
range. Those queries all work fine.
My trouble is that when trying to pull in all the data, I can't seem
to match the product and warehouses for the four queries together to
get me a combined output. Just to make things more difficult, not all
periods are listed for each product/warehouse combination meaning that
I cannot simply join all product fields and all warehouse fields
together. I may "lose" data. At least that's what my tests showed.
I've tried using the base table UV_SPPROD to perform a left join but
seem to get cartesian joins with the data or lost data. I've also
tried a union with zeros as placeholders. That will work if I create
a final query to sum based on product and warehouse. I'm hoping to
create one query that will write the information.
Any help is appreciated.
-Chris
Comment