I think there might be a way to partition this to find what I want, but I can't see it. I have some slightly unnormalized data about product sets:
SetItemID ComponentItemID quantity IsPrimary
123 234 1 1
123 345 2 0
456 567 3 1
456 678 2 0
I need to find sets where the quantity
's described are, for example, IsPrimary
component's quantity
> 'IsPrimary=0component's
quantity. I also need to find sets where quantities are equal between components, etc. It's ok to use multiple statements for this, if necessary
All I have so far is a partial PARTITION
statement that may or may not be the right way to do this, but I can't figure out how to compare quantities within sets:
WITH setdata as
(select *, row_number() OVER(
PARTITION by s.setitemid order by s.setitemid) position from set_table s )
// descending just to get newer sets
SELECT* from setdata order by setitemid desc