Okay, I'll try to explain this as best as I can. I have a table which houses every product we have in stock and their properties. There are four fields that I'm interested in: Prod_type,Gemstone,Retail_cat, and Meterial. I need to find unique combination of the products based on 1,2,3,or 4 of these properties. IE, one grouping would include them all, another would be just the first three, however, another might be the first two and the last one. There are a possible 16 combinations (including grouping by none,which doesn't make sense). So far I've written 15 queries and thrown them all in a table. I'm sure there is an easier way, but its done now. Here comes the hard part. Those 15 queries produced 5500 results. I also have an orders table. I need to get the top 10 items for each of the items in the aforementioned table???? Without doing 15 more separate queries with a rank() over taking just the top 10, I'm not sure how else to do it?? Am I making any sense at all?
This is the query used to get the ranking on a group by all 4:
select (rank() over
(order by sum(qty) desc)) as Rank,
a.product_id,c.prod_type,c.retail_cat,c.material_type,c.gemstone,sum(qty) total
from acntv.litem a,
acntv.sku b,
acntv.master_sku c
where a.product_id=b.product_id and
b.master_id=c.master_id and
order_date between sysdate-1 and sysdate and
litem_id=1
group by a.product_id,c.prod_type,c.retail_cat,c.material_type,c.gemstone
order by rank
It looks as if I'll have to do 14 other queries based on the different grouping combinations and then run a cursor to insert them into the first table mentioned in the appropriate rank field. If you have questions, and certainly if you have any advice, please let me know. Thanks
This is the query used to get the ranking on a group by all 4:
select (rank() over
(order by sum(qty) desc)) as Rank,
a.product_id,c.prod_type,c.retail_cat,c.material_type,c.gemstone,sum(qty) total
from acntv.litem a,
acntv.sku b,
acntv.master_sku c
where a.product_id=b.product_id and
b.master_id=c.master_id and
order_date between sysdate-1 and sysdate and
litem_id=1
group by a.product_id,c.prod_type,c.retail_cat,c.material_type,c.gemstone
order by rank
It looks as if I'll have to do 14 other queries based on the different grouping combinations and then run a cursor to insert them into the first table mentioned in the appropriate rank field. If you have questions, and certainly if you have any advice, please let me know. Thanks