How to get rows having sum equal to given value

后端 未结 4 930
南旧
南旧 2020-12-19 10:19

There is table contain

ID     Qty
----------
1       2
2       4
3       1
4       5

Now if i had to choose rows where sum of Qty equals to

4条回答
  •  生来不讨喜
    2020-12-19 11:05

    If u add always 3 numbers its like gbn said, if not then u have to check every combination of ur rows which gives u 2 to the number_of_rows power cobinations and i dont see how can it be done on sql in one query. If u use loop in sql sure its possible but u should find some good algorithm to finish this task.

提交回复
热议问题