Home > Database > Mysql Tutorial > What is the function of mysql query quadrature?

What is the function of mysql query quadrature?

藏色散人
Release: 2020-11-03 09:44:00
Original
4545 people have browsed it

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".

What is the function of mysql query quadrature?

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
Copy after login

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!

Related labels:
sql
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template