我认为可能有办法对此进行分区以找到我想要的,但我看不到它。我有关于产品集的一些略微非标准化数据:SQL Server分区非标准化数据
SetItemID ComponentItemID quantity IsPrimary
123 234 1 1
123 345 2 0
456 567 3 1
456 678 2 0
我需要找到套其中quantity
“描述s为,例如,IsPrimary
组件的quantity
>”值isPrimary = 0 component's
量。我还需要找到集合,其中数量是组件之间的平等,等等这是确定用于该多条语句,如果必要的话
所有我到目前为止是部分PARTITION
声明,可能会或可能不会是正确的办法做到这一点,但我无法弄清楚如何套内比较量:
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