繁体   English   中英

如何在SQL Server的while循环中使用select语句检索记录?

[英]How to retrieve records using select statement in while loop in SQL Server?

我有2个表,分别称为ProductProductDetails

我的标准很困难。 我不知道该怎么做。

因此,再次将ProductDetails记录移至临时表,现在余额为15-12 = 3,现在检查第3个转移数量10,现在3 <10为真。 现在将此记录也存储到临时表

您能提出解决方案吗?

如果我理解正确的话,你最想要的最近日期的累积量在productdetails达到或超过的数量我product 这是一个累积的总和join

select pd.*
from (select pd.*,
             sum(Quantity) over (partition by ProductID       order by DateTransferred desc) as running_quantity
      from productdetails pd
     ) pd join
     product p
     on p.productid = pd.productid and
        p.quantity >= (pd.runningquantity - pd.quantity);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM