Instantly share code, notes, and snippets.

Embed
What would you like to do?
MISQUERY ONLINE
WITH RECURSIVE solve(min, max, n) AS (
VALUES(1.0, 2.1, 0)
UNION ALL
SELECT
(
CASE WHEN t.a * POWER( 2.718281828459045235360287471352, (s.min + s.max) / 2) + t.b * POW((s.min + s.max) / 2, 3) + t.c * (s.min + s.max) / 2 + t.d > 0 THEN
s.min
ELSE
(s.min + s.max) / 2
END
),
(
CASE WHEN t.a * POWER( 2.718281828459045235360287471352, (s.min + s.max) / 2) + t.b * POW((s.min + s.max) / 2, 3) + t.c * (s.min + s.max) / 2 + t.d > 0 THEN
(s.min + s.max) / 2
ELSE
max
END
),
n+1
FROM (SELECT a,b,c,d FROM tbl) AS t, solve AS s
WHERE n < 100
)
SELECT MAX(min) AS solution FROM solve LIMIT 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment