What you intend to solve is called linear programming. A simple form of it, but still.
In general LP is not in the scope of any database engine. Solver can do this for you in Excel, but of course there are standalone programs and libraries you can use. Of course if you know the algoritm, you might be able to program it using one or the other RDBMS (check these considerations:
https://www.simple-talk.com/sql/t-sql-programming/matrix-math-in-sql/[
^]). Google for "simplex method" for the algoritm.