How to Find the Closest Subset Sum with SQL | Java, SQL and jOOQ.
Java, SQL and jOOQ. Best Practices and Lessons Learned from Writing Awesome Java and SQL Code. Get some hands-on insight on what's behind developing jOOQ. How to Find the Closest Subset Sum with SQL I've stumbled upon this very interesting question on Stack Overflow, recently. Its title is: Recursive SQL The problem The user alhashmiya who had asked this question, was looking for a solution to the problem of finding the "closest" sum of elements in a subset of numbers A to a set of "expected" sums B. More concretely, alhasmiya had the following two tables: ID ASSIGN_AMT -------------- 1 25150 2 19800 3 27511 And… ID WORK_AMT ------------ 1 7120 2 8150 3 8255 4 9051 5 1220 6 12515 7 13555 8 5221 9 812 10 6562 The ASSIGN_AMT value is the "expected" sum. What alhashmiya was looking for is the sum of a subset of WORK_AMT values A, such that this sum is as close as possible to any of the "expected" sums.Read full article from How to Find the Closest Subset Sum with SQL | Java, SQL and jOOQ.
No comments:
Post a Comment