重现步骤

[步骤]

UPDATE RB_Product
SET    [UpdateTime] = Getdate(),
       LastSupplierPrice = 15.0000
WHERE  SKU = '9071700'
       AND CustomerID = 1; --修改组合产品供货价                          

UPDATE RB_Product
SET    UpdateTime = Getdate(),
       RB_Product.LastSupplierPrice = (SELECT Sum(p.LastSupplierPrice * g.SkuNum)
                                       FROM   RB_Product p WITH (NOLOCK)
                                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                                ON p.SKU = g.SKU
                                                   AND p.CustomerID = g.CustomerID
                                       WHERE  g.GroupSku = RB_Product.SKU
                                              AND g.CustomerID = 1)
FROM   RB_Product
WHERE  SKU IN (SELECT DISTINCT GroupSku
               FROM   RB_Product_GroupSku WITH ( NOLOCK )
               WHERE  SKU = '9071700'
                      AND CustomerID = 1)
       AND CustomerID = 1 --修改组合产品供货价,产品价,打包费   

UPDATE a
SET    a.UpdateTime = Getdate(),
       a.SupplierPrice = (SELECT Sum(Isnull(p.SupplierPrice, 0) * g.SkuNum)
                          FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                 INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                   ON p.SKU = g.SKU
                                      AND p.CustomerID = g.CustomerID
                                      AND p.IsDefault = 1
                          WHERE  g.CustomerID = 1
                                 AND g.GroupSku = a.sku),
       a.SupplierProductPrice = (SELECT Sum(Isnull(p.SupplierProductPrice, 0) * g.SkuNum)
                                 FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                        INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                          ON p.SKU = g.SKU
                                             AND p.CustomerID = g.CustomerID
                                             AND p.IsDefault = 1
                                 WHERE  g.CustomerID = 1
                                        AND g.GroupSku = a.sku),
       a.PackingFee = (SELECT Sum(Isnull(p.PackingFee, 0) * g.SkuNum)
                       FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                ON p.SKU = g.SKU
                                   AND p.CustomerID = g.CustomerID
                                   AND p.IsDefault = 1
                       WHERE  g.CustomerID = 1
                              AND g.GroupSku = a.sku)
FROM   RB_Product_SupplierPrice a
WHERE  a.IsDefault = 1
       AND a.SKU IN (SELECT DISTINCT GroupSku
                     FROM   RB_Product_GroupSku WITH (NOLOCK)
                     WHERE  SKU = '9071700'
                            AND CustomerID = 1)
       AND a.CustomerID = 1

UPDATE RB_Product
SET    [UpdateTime] = Getdate(),
       LastSupplierPrice = 14.0000
WHERE  SKU = '8297067'
       AND CustomerID = 1; --修改组合产品供货价 

UPDATE RB_Product
SET    UpdateTime = Getdate(),
       RB_Product.LastSupplierPrice = (SELECT Sum(p.LastSupplierPrice * g.SkuNum)
                                       FROM   RB_Product p WITH (NOLOCK)
                                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                                ON p.SKU = g.SKU
                                                   AND p.CustomerID = g.CustomerID
                                       WHERE  g.GroupSku = RB_Product.SKU
                                              AND g.CustomerID = 1)
FROM   RB_Product
WHERE  SKU IN (SELECT DISTINCT GroupSku
               FROM   RB_Product_GroupSku WITH ( NOLOCK )
               WHERE  SKU = '8297067'
                      AND CustomerID = 1)
       AND CustomerID = 1 --修改组合产品供货价,产品价,打包费 

UPDATE a
SET    a.UpdateTime = Getdate(),
       a.SupplierPrice = (SELECT Sum(Isnull(p.SupplierPrice, 0) * g.SkuNum)
                          FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                 INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                   ON p.SKU = g.SKU
                                      AND p.CustomerID = g.CustomerID
                                      AND p.IsDefault = 1
                          WHERE  g.CustomerID = 1
                                 AND g.GroupSku = a.sku),
       a.SupplierProductPrice = (SELECT Sum(Isnull(p.SupplierProductPrice, 0) * g.SkuNum)
                                 FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                        INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                          ON p.SKU = g.SKU
                                             AND p.CustomerID = g.CustomerID
                                             AND p.IsDefault = 1
                                 WHERE  g.CustomerID = 1
                                        AND g.GroupSku = a.sku),
       a.PackingFee = (SELECT Sum(Isnull(p.PackingFee, 0) * g.SkuNum)
                       FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                ON p.SKU = g.SKU
                                   AND p.CustomerID = g.CustomerID
                                   AND p.IsDefault = 1
                       WHERE  g.CustomerID = 1
                              AND g.GroupSku = a.sku)
FROM   RB_Product_SupplierPrice a
WHERE  a.IsDefault = 1
       AND a.SKU IN (SELECT DISTINCT GroupSku
                     FROM   RB_Product_GroupSku WITH (NOLOCK)
                     WHERE  SKU = '8297067'
                            AND CustomerID = 1)
       AND a.CustomerID = 1

UPDATE RB_Product
SET    [UpdateTime] = Getdate(),
       LastSupplierPrice = 4.3000
WHERE  SKU = '6600740'
       AND CustomerID = 1; --修改组合产品供货价  

UPDATE RB_Product
SET    UpdateTime = Getdate(),
       RB_Product.LastSupplierPrice = (SELECT Sum(p.LastSupplierPrice * g.SkuNum)
                                       FROM   RB_Product p WITH (NOLOCK)
                                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                                ON p.SKU = g.SKU
                                                   AND p.CustomerID = g.CustomerID
                                       WHERE  g.GroupSku = RB_Product.SKU
                                              AND g.CustomerID = 1)
FROM   RB_Product
WHERE  SKU IN (SELECT DISTINCT GroupSku
               FROM   RB_Product_GroupSku WITH ( NOLOCK )
               WHERE  SKU = '6600740'
                      AND CustomerID = 1)
       AND CustomerID = 1 --修改组合产品供货价,产品价,打包费    

UPDATE a
SET    a.UpdateTime = Getdate(),
       a.SupplierPrice = (SELECT Sum(Isnull(p.SupplierPrice, 0) * g.SkuNum)
                          FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                 INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                   ON p.SKU = g.SKU
                                      AND p.CustomerID = g.CustomerID
                                      AND p.IsDefault = 1
                          WHERE  g.CustomerID = 1
                                 AND g.GroupSku = a.sku),
       a.SupplierProductPrice = (SELECT Sum(Isnull(p.SupplierProductPrice, 0) * g.SkuNum)
                                 FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                        INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                          ON p.SKU = g.SKU
                                             AND p.CustomerID = g.CustomerID
                                             AND p.IsDefault = 1
                                 WHERE  g.CustomerID = 1
                                        AND g.GroupSku = a.sku),
       a.PackingFee = (SELECT Sum(Isnull(p.PackingFee, 0) * g.SkuNum)
                       FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                ON p.SKU = g.SKU
                                   AND p.CustomerID = g.CustomerID
                                   AND p.IsDefault = 1
                       WHERE  g.CustomerID = 1
                              AND g.GroupSku = a.sku)
FROM   RB_Product_SupplierPrice a
WHERE  a.IsDefault = 1
       AND a.SKU IN (SELECT DISTINCT GroupSku
                     FROM   RB_Product_GroupSku WITH (NOLOCK)
                     WHERE  SKU = '6600740'
                            AND CustomerID = 1)
       AND a.CustomerID = 1

UPDATE RB_Product
SET    [UpdateTime] = Getdate(),
       LastSupplierPrice = 14.4000
WHERE  SKU = '17693953'
       AND CustomerID = 1; --修改组合产品供货价  

UPDATE RB_Product
SET    UpdateTime = Getdate(),
       RB_Product.LastSupplierPrice = (SELECT Sum(p.LastSupplierPrice * g.SkuNum)
                                       FROM   RB_Product p WITH (NOLOCK)
                                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                                ON p.SKU = g.SKU
                                                   AND p.CustomerID = g.CustomerID
                                       WHERE  g.GroupSku = RB_Product.SKU
                                              AND g.CustomerID = 1)
FROM   RB_Product
WHERE  SKU IN (SELECT DISTINCT GroupSku
               FROM   RB_Product_GroupSku WITH ( NOLOCK )
               WHERE  SKU = '17693953'
                      AND CustomerID = 1)
       AND CustomerID = 1 --修改组合产品供货价,产品价,打包费   

UPDATE a
SET    a.UpdateTime = Getdate(),
       a.SupplierPrice = (SELECT Sum(Isnull(p.SupplierPrice, 0) * g.SkuNum)
                          FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                 INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                   ON p.SKU = g.SKU
                                      AND p.CustomerID = g.CustomerID
                                      AND p.IsDefault = 1
                          WHERE  g.CustomerID = 1
                                 AND g.GroupSku = a.sku),
       a.SupplierProductPrice = (SELECT Sum(Isnull(p.SupplierProductPrice, 0) * g.SkuNum)
                                 FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                        INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                          ON p.SKU = g.SKU
                                             AND p.CustomerID = g.CustomerID
                                             AND p.IsDefault = 1
                                 WHERE  g.CustomerID = 1
                                        AND g.GroupSku = a.sku),
       a.PackingFee = (SELECT Sum(Isnull(p.PackingFee, 0) * g.SkuNum)
                       FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                ON p.SKU = g.SKU
                                   AND p.CustomerID = g.CustomerID
                                   AND p.IsDefault = 1
                       WHERE  g.CustomerID = 1
                              AND g.GroupSku = a.sku)
FROM   RB_Product_SupplierPrice a
WHERE  a.IsDefault = 1
       AND a.SKU IN (SELECT DISTINCT GroupSku
                     FROM   RB_Product_GroupSku WITH (NOLOCK)
                     WHERE  SKU = '17693953'
                            AND CustomerID = 1)
       AND a.CustomerID = 1

UPDATE RB_Product
SET    [UpdateTime] = Getdate(),
       LastSupplierPrice = 28.0000
WHERE  SKU = '14945233'
       AND CustomerID = 1; --修改组合产品供货价 

UPDATE RB_Product
SET    UpdateTime = Getdate(),
       RB_Product.LastSupplierPrice = (SELECT Sum(p.LastSupplierPrice * g.SkuNum)
                                       FROM   RB_Product p WITH (NOLOCK)
                                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                                ON p.SKU = g.SKU
                                                   AND p.CustomerID = g.CustomerID
                                       WHERE  g.GroupSku = RB_Product.SKU
                                              AND g.CustomerID = 1)
FROM   RB_Product
WHERE  SKU IN (SELECT DISTINCT GroupSku
               FROM   RB_Product_GroupSku WITH ( NOLOCK )
               WHERE  SKU = '14945233'
                      AND CustomerID = 1)
       AND CustomerID = 1 --修改组合产品供货价,产品价,打包费  

UPDATE a
SET    a.UpdateTime = Getdate(),
       a.SupplierPrice = (SELECT Sum(Isnull(p.SupplierPrice, 0) * g.SkuNum)
                          FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                 INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                   ON p.SKU = g.SKU
                                      AND p.CustomerID = g.CustomerID
                                      AND p.IsDefault = 1
                          WHERE  g.CustomerID = 1
                                 AND g.GroupSku = a.sku),
       a.SupplierProductPrice = (SELECT Sum(Isnull(p.SupplierProductPrice, 0) * g.SkuNum)
                                 FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                        INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                          ON p.SKU = g.SKU
                                             AND p.CustomerID = g.CustomerID
                                             AND p.IsDefault = 1
                                 WHERE  g.CustomerID = 1
                                        AND g.GroupSku = a.sku),
       a.PackingFee = (SELECT Sum(Isnull(p.PackingFee, 0) * g.SkuNum)
                       FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                ON p.SKU = g.SKU
                                   AND p.CustomerID = g.CustomerID
                                   AND p.IsDefault = 1
                       WHERE  g.CustomerID = 1
                              AND g.GroupSku = a.sku)
FROM   RB_Product_SupplierPrice a
WHERE  a.IsDefault = 1
       AND a.SKU IN (SELECT DISTINCT GroupSku
                     FROM   RB_Product_GroupSku WITH (NOLOCK)
                     WHERE  SKU = '14945233'
                            AND CustomerID = 1)
       AND a.CustomerID = 1

UPDATE RB_Product
SET    [UpdateTime] = Getdate(),
       LastSupplierPrice = 5.8900
WHERE  SKU = '12029613'
       AND CustomerID = 1; --修改组合产品供货价    

UPDATE RB_Product
SET    UpdateTime = Getdate(),
       RB_Product.LastSupplierPrice = (SELECT Sum(p.LastSupplierPrice * g.SkuNum)
                                       FROM   RB_Product p WITH (NOLOCK)
                                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                                ON p.SKU = g.SKU
                                                   AND p.CustomerID = g.CustomerID
                                       WHERE  g.GroupSku = RB_Product.SKU
                                              AND g.CustomerID = 1)
FROM   RB_Product
WHERE  SKU IN (SELECT DISTINCT GroupSku
               FROM   RB_Product_GroupSku WITH ( NOLOCK )
               WHERE  SKU = '12029613'
                      AND CustomerID = 1)
       AND CustomerID = 1 --修改组合产品供货价,产品价,打包费    

UPDATE a
SET    a.UpdateTime = Getdate(),
       a.SupplierPrice = (SELECT Sum(Isnull(p.SupplierPrice, 0) * g.SkuNum)
                          FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                 INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                   ON p.SKU = g.SKU
                                      AND p.CustomerID = g.CustomerID
                                      AND p.IsDefault = 1
                          WHERE  g.CustomerID = 1
                                 AND g.GroupSku = a.sku),
       a.SupplierProductPrice = (SELECT Sum(Isnull(p.SupplierProductPrice, 0) * g.SkuNum)
                                 FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                        INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                          ON p.SKU = g.SKU
                                             AND p.CustomerID = g.CustomerID
                                             AND p.IsDefault = 1
                                 WHERE  g.CustomerID = 1
                                        AND g.GroupSku = a.sku),
       a.PackingFee = (SELECT Sum(Isnull(p.PackingFee, 0) * g.SkuNum)
                       FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                              INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                ON p.SKU = g.SKU
                                   AND p.CustomerID = g.CustomerID
                                   AND p.IsDefault = 1
                       WHERE  g.CustomerID = 1
                              AND g.GroupSku = a.sku)
FROM   RB_Product_SupplierPrice a
WHERE  a.IsDefault = 1
       AND a.SKU IN (SELECT DISTINCT GroupSku
                     FROM   RB_Product_GroupSku WITH (NOLOCK)
                     WHERE  SKU = '12029613'
                            AND CustomerID = 1)
       AND a.CustomerID = 1 


[结果]


[期望]

语句过长 SQL 简析慢,建议拆分 优先把值算出来 然后再处理 

SELECT DISTINCT GroupSku
               FROM   RB_Product_GroupSku WITH ( NOLOCK )
               WHERE  SKU = '9071700'
                      AND CustomerID = 1
改语句 优先 算出 SKU  然后在带入 其他SQL 运算

而且 该SQL 应该 改成 


SELECT top 1 GroupSku
               FROM   RB_Product_GroupSku WITH ( NOLOCK )
               WHERE  SKU = '9071700'
                      AND CustomerID = 1

优先 算出 值

同一个 SKU 不存在 与多个 组合SKU 中 



下个子查询 也优先算出来  SupplierPrice SupplierProductPrice  PackingFee


   SELECT Sum(Isnull(p.SupplierPrice, 0) * g.SkuNum) SupplierPrice,  Sum(Isnull(p.SupplierProductPrice, 0) * g.SkuNum) SupplierProductPrice,Sum(Isnull(p.PackingFee, 0) * g.SkuNum) PackingFee
                          FROM   RB_Product_SupplierPrice p WITH (NOLOCK)
                                 INNER JOIN RB_Product_GroupSku g WITH (NOLOCK)
                                   ON p.SKU = g.SKU
                                      AND p.CustomerID = g.CustomerID
                                      AND p.IsDefault = 1
                          WHERE  g.CustomerID = 1
                                 AND g.GroupSku =  '9071700'
然后带入 需要处理的SQL 。这样 后面 更新的 SQL 语句 就变得简单易执行 

历史记录  
  1. 2026-08-21 15:09:45, 由 袁慧斌 创建。
  2. 2026-08-21 15:11:20, 由 李乐同 指派给 何建宝。
    修改了 指派给,旧值为 "liletong",新值为 "hejianbao"。
  3. 2026-08-21 15:19:04, 由 何建宝 指派给 宋宇。
    修改了 指派给,旧值为 "hejianbao",新值为 "songyu"。
  4. 2026-08-21 18:25:19, 由 宋宇 指派给 何建宝。
    修改了 指派给,旧值为 "songyu",新值为 "hejianbao"。
    已处理
  5. 2026-08-21 18:29:41, 由 何建宝 解决,方案为 性能问题 。
    修改了 解决方案,旧值为 "",新值为 "performance"。
    修改了 解决版本,旧值为 "",新值为 "trunk"。
    修改了 解决日期,旧值为 "",新值为 "2026-08-21 18:29:20"。
    修改了 指派给 ,旧值为 "hejianbao",新值为 "yuanhuibin"。
    修改了 Bug状态 ,旧值为 "active",新值为 "resolved"。
    修改了 是否确认,旧值为 "0",新值为 "1"。
    修改了 解决者 ,旧值为 "",新值为 "hejianbao"。
    已处理,待发版
  6. 2026-08-21 18:30:16, 由 何建宝 编辑。
    修改了 开发责任人,旧值为 "",新值为 "ZengXiang"。
    修改了 解决时效 ,旧值为 "0",新值为 "3.33"。
  7. 2026-08-26 11:06:42, 由 袁慧斌 编辑。
    修改了 截止日期,旧值为 "0000-00-00",新值为 "2026-08-25"。
    修改了 上线时间,旧值为 "0000-00-00 00:00:00",新值为 "2026-08-25 18:30"。
    修改了 上线时效,旧值为 "-1",新值为 "51.34"。
  8. 2026-08-26 11:06:54, 由 袁慧斌 编辑。
    修改了 测试责任人,旧值为 "",新值为 "admin"。
  9. 2026-08-26 11:06:57, 由 袁慧斌 关闭。
    修改了 Bug状态 ,旧值为 "resolved",新值为 "closed"。
    修改了 指派给 ,旧值为 "yuanhuibin",新值为 "closed"。
    修改了 由谁关闭,旧值为 "",新值为 "yuanhuibin"。
    修改了 关闭日期,旧值为 "",新值为 "2026-08-26 11:06:57"。
  10. 2026-09-02 08:54:06, 由 陈莉珍 编辑。
    修改了 测试责任人,旧值为 "admin",新值为 "ZengXiang"。
    修改了 上线时间 ,旧值为 "2026-08-25 18:30:00",新值为 "2026-08-21 18:29:41"。
    修改了 上线时效 ,旧值为 "51.34",新值为 "3.33"。
所属项目 技术中心-需求池
所属模块 供应链   产品采购   产品库
所属计划
所属迭代
Bug类型
严重程度 一般
优先级 P1
Bug状态 已关闭
业务部门
影响功能
开发责任人 曾翔
测试责任人 曾翔
解决时效 3.33
激活次数 0
激活日期
是否确认 是
当前指派 Closed 于 2026-09-02 08:54:06
截止日期 2026-08-25
上线时间 2026-08-21 18:29:41
上线时效 3.33
操作系统
浏览器
关键词
抄送给
所属迭代
相关需求
相关任务
由谁创建 袁慧斌 于 2026-08-21 15:09:45
影响环境 生产环境-业务反馈
由谁解决 何建宝 于 2026-08-21 18:29:20
解决版本 主干
解决方案 性能问题
由谁关闭 袁慧斌 于 2026-08-26 11:06:57
最后修改 陈莉珍 于 2026-09-02 08:54:06
相关Bug