临时表:
CREATE TABLE #temphistory(skuid UNIQUEIDENTIFIER,shipping_order_sku_id UNIQUEIDENTIFIER, amount int,sort int)
插入数据:
INSERT INTO #temphistory
SELECT [ShippingOrderSku].SkuId,[ShippingOrderSku].Id,[ShippingOrderSku].Amount,ROW_NUMBER() OVER (PARTITION BY SkuId ORDER BY (SELECT NULL)) FROM
[dbo].[ShippingOrderSku]
INNER JOIN @packable_order_ids ON [dbo].[ShippingOrderSku].[OrderId] = [@packable_order_ids].[id];
mssql CTE查询:
;WITH cte AS
(
SELECT * FROM #temphistory WHERE sort=1
UNION ALL
SELECT #temphistory.skuid,#temphistory.shipping_order_sku_id,#temphistory.amount+cte.amount,#temphistory.sort
FROM cte INNER JOIN #temphistory
ON #temphistory.skuid = cte.skuid AND #temphistory.sort=cte.sort+1
)
如何在MySQL中使用“WITH”子句查询?