What is a function? How to use functions to improve the efficiency of numerical calculations?

In the previous article, we discussed how to use FETCH (or LIMIT) and OFFSET to achieve Top-N ranking and paging query of data.

The main function of SQL statements is to process and analyze data. In order to avoid duplication of wheels and improve the efficiency of data processing, SQL provides us with many standard function modules: Function. In fact, we have used SQL functions, such as the UPPER function to convert characters to uppercase.

Function overview

An SQL function is a module with a certain function that can receive zero or more input values ​​and return an output value. The process of function processing data is shown in the figure below:

avatar

In SQL, functions are mainly divided into two types:

  • Scalar function. The scalar function returns an output result for each input parameter. For example, ABS(x) can calculate the absolute value of x.
  • Aggregate function . Aggregate functions perform calculations based on a set of data and return an output result. For example, the AVG function can calculate the average of a set of data.

Let's introduce scalar functions first, and aggregate functions will be introduced in Part 12. To facilitate learning, we divide common SQL scalar functions into the following categories: numeric functions , character functions , date functions, and type conversion functions . This article only deals with numerical functions.

Numerical function

Numerical functions usually accept numeric parameters and execute

Guess you like

Origin blog.csdn.net/horses/article/details/108729111