There is no function for querying multiplication in mysql, but multiplication can be achieved through the "logx logy=logx*y" calculation. The specific SQL statement is such as "select exp(sum(log(col))) from table where id<100".
Recommended: "mysql video tutorial"
There are many aggregate functions in sql, such as COUNT, SUM, MIN and MAX.
But there is no multiplication function, and many friends need to use this function during development. Today I will tell you a good solution
logx logy=logx*y
This is the logarithm calculation we learned in high school. The addition of logarithms is equal to the multiplication of exponents. We use this method to convert addition to multiplication.
Implementation method, first Record log(), then sum aggregation, and finally exp, the result is the result of recording multiplication
select exp(sum(log(col))) from table where id<100
The example is as follows:
Correct, Friends who don’t believe it can manually calculate the data in my picture, O(∩_∩)O~
The above is the detailed content of What is the function of mysql query quadrature?. For more information, please follow other related articles on the PHP Chinese website!