求个逻辑或算法
举例
list:
Rid Rname pid iid invetory pickcount cfcount result
1 架001 1 1 3 5 0 3 -- 此值是invetory的值
2 架002 1 2 11 5 0 5
3 架003 1 1 2 5 0 2 -- 此值是(架001)pickcount的值跟iid(pid)相同的架003的invetory的值对比,不超过invetory,然后计算出(5-3)得出来的值
另一种情况的list:
Rid Rname pid iid invetory pickcount cfcount result
1 架001 1 1 3 5 4 0 (cfcount大于invetory,所以此值,是为0,但剩下的还有1个)
2 架002 1 2 11 5 5 0
3 架003 1 1 2 5 4 1 (第一行记录,剩下的1个,与invetory进行相减,得到1)
以上的算法,该怎么的一种逻辑,或是怎么计算出来。谢谢!!