Skip to main content

Posts

Showing posts with the label SQL

How to calculate the infinite product by SQL

How to calculate the infinite product by SQL Description I needed to calculate the infinite product in the creating ETL script. So I thought the solution to calculate it in the SQL. The following way is the solution I thought. Premise Use the standard SQL Code WITH sample_table AS ( SELECT 2 AS n1, 4 AS n2 UNION ALL SELECT 4 , 8 UNION ALL SELECT 10 , 20 UNION ALL SELECT 10 , 20 ) SELECT * FROM sample_table UNION ALL SELECT CAST ( EXP ( SUM ( LOG (n1))) AS INT64) AS inf_product1, CAST ( EXP ( SUM ( LOG (n2))) AS INT64) AS inf_product2 FROM sample_table The infinite product (∏) is able to convert to the total addition formula. ∏n1 ≒ e Σlog e n1 ∏n2 ≒ e Σlog e n2 Finally Actually, this calculated value is an approximation. So if you want an accurate number, this solution cannot use.