Since many of the data in the database are digital, one important use is to be able to perform calculations on these numbers, such as aggregating them together or finding their average. SQL has a function that provides some of this type. They are:
- AVG Average
- COUNT Count
- MAX (maximum value)
- MIN (Minimum value)
- SUM Sum
The syntax for applying a function is:
Select "Function name" ("Field name")
From "table name";
For example, if we were to find the sum of the Sales fields from our demo table,
store_information Form
Store_name |
Sales |
Txn_date |
Los Angeles |
1500 |
05-jan-1999 |
San Diego |
250 |
07-jan-1999 |
Los Angeles |
300 |
08-jan-1999 |
Boston |
700 |
08-jan-1999 |
We'll break in,
SELECT SUM (Sales) from Store_information;
Results:
2750 represents the sum of all Sales fields: 1500 + 250 + 300 + 700.
In addition to the use of functions, SQL can also do simple mathematical operations, such as add (+) and minus (-). For the text class data, SQL also has several functions of word processing, such as text connection (concatenation), text trimming (trim), and sub-string (substring ). Different databases have different syntax for these functions, so it is best to refer to the information of the database you are using to determine how these functions are used in that database.
Linux is measured as follows:
Reprint please specify: Xiao Liu
Linux SQL statement Concise tutorial---functions