4 ms·
Working extensively in SQL for a while also gives you another perspective of programming. There is just no way you can write this with a for loop in SQL since i
by fifilura 2y ago
Working extensively in SQL for a while also gives you another perspective of programming. There is just no way you can write this with a for loop in SQL since it does not (generally) have for loops.
WITH all_numbers AS
(
SELECT generate_series as n
FROM generate_series(1, 108) as n
),
divisors AS
(
SELECT *
FROM all_numbers
WHERE 108 % n = 0
),
permutations as
(
SELECT a.n as n1, b.n as n2, c.n as n3
FROM divisors as a
CROSS JOIN divisors as b
CROSS JOIN divisors as c
)
SELECT *
FROM permutations
WHERE n1 * n2 * n3 = 108
AND n1 < n2 And n2 < n3
ORDER BY n1, n2, n3
https://codapi.org/embed/?sandbox=duckdb&code=data%3A%3Bbase64%2CfY%2FNCsIwEITveYq5CFaKWHvxoIeqERW1kAriSVINUtBVmurzm43iH2IOybITvplZTZZj6MNhQ5djbkqLJBN1AXcyOZODJfaGTKkrs7GmLIyFtiCvj1Q6%2F1brUYio1Qnuv4JQ7IprYU8%2FsI0X483dL1djqSRjUAOhhxaDzqY8XipdFSfiDJ8w3STv6Nzzx9gOsX2M8cvqGcfttV8PVJplmKaTxYeY%2FxO3IoB49vDg93jiXoAiNFwOvmLXggt5aLIYstZlLaEdP13%2BIlI1lAr9NXwRbkDxDQ%3D%3D https://codapi.org/embed/?sandbox=duckdb&code=data%3A%3Bbase...