我正在尝试创建一个自定义汇总逻辑,以应用于在不同BOM级别(物料清单)中提取“小计”的查询。我试图使用group by的汇总函数,但它不会在汇总中拾取正确的行(参见图片)。例如,第3行应该包含行3,4,5和6.第5行(bom level 2)汇总应该只包括5和6(bom level 3)。这是我到目前为止所拥有的。感谢任何建议。感谢
CREATE TABLE #BOM_ALL
(
SORT_PATH VARCHAR(1000) ,
BOM_LEVEL VARCHAR(12),
PART_NO VARCHAR(125),
COMPONENT_NO VARCHAR(125),
PART_QUANTITY DECIMAL(18,5),
COMPONENT_QUANTITY DECIMAL(18,5),
HOURS DECIMAL(18,5),
LOGIC_ROLLUP_RESULTS DECIMAL(18,5)
);
INSERT #BOM_ALL
VALUES
('650.5104',0,'650.5104','',1.00000,1.000000, 14.784, 122.084),
('650.5104~~600.1383',1,'650.5104','600.1383',1.00000,1.000000,0.20000,
0.20000),
('650.5104~~647.6004',1,'650.5104','647.6004',1.00000, 1.000000, 53.43299,
96.57536),
('650.5104~~647.6004~~647.6008',2,'650.5104','647.6008',1.00000, 1.000000,
38.29316, 43.14237),
('650.5104~~647.6004~~647.6009',2,'650.5104','647.6009',1.00000, 1.000000,
4.84921, 5.09921),
('650.5104~~647.6004~~647.6009~~650.6005',3,'650.5104','650.6005',1.00000,
1.000000, 0.25000, 0.25000),
('650.5104~~647.6004~~648.3304',2,'650.5104','648.3304',1.00000, 1.000000,
4.82947,7.36961),
('650.5104~~647.6004~~648.3304~~648.3346',3,'650.5104','600.3346',1.00000,
4.000000, 0.64749,2.58994),
('650.5104~~647.6004~~648.3305',2,'650.5104','600.3346',1.00000, 1.000000,
2.54014,5.08028),
('650.5104~~647.6004~~648.3304~~648.3346',3,'650.5104','600.3346',1.00000,
4.000000, 0.64749,2.58994),
('650.5104~~647.6004~~648.3310',2,'650.5104','600.3346',1.00000, 1.000000,
1.61005,1.61005)
SELECT
SORT_PATH,
BOM_LEVEL,
PART_NO,
COMPONENT_NO,
PART_QUANTITY,
COMPONENT_QUANTITY,
HOURS,
LOGIC_ROLLUP_RESULTS as ROLLUP_HOURS
FROM #BOM_ALL