Chapter 5 Aggregate Functions and Built-in Functions
- 1. Aggregation function
- 2. Built-in functions
- 4. Other functions
-
- 1. user query current user
- (2) md5(str) performs an md5 digest on a string str, and obtains a 32-bit string after the digest
- (3) database() displays the database currently in use
- (4) password() function, MySQL database uses this function to encrypt users
- (5) ifnull(val1, val2) If val1 is null, return val2, otherwise return the value of val1
1. Aggregation function
1. Commonly used aggregation functions
2. Examples
(1)count
Count the number of students in the class.
Count the number of qq numbers collected by the class.
Before doing this requirement, we first create a table and insert certain data as shown in the figure below:
Now let's check how many qq numbers there are. As can be seen from the above figure, there are a total of 3 qq numbers.
(2)sum
The total score of the statistical mathematics achievement.
(3)avg
The average score of the total scores of the three subjects of Chinese, Mathematics and English in the statistical score sheet.
(4)max
Returns the highest score for the English score.
(5)min
Returns > 70+ minimum score in mathematics
2. Built-in functions
1. Date function
(1) Overview
(2) Example
Obtain year, month, day:
Obtain hour, minute, second:
Obtain timestamp:
Add a date to a date:
Subtract a date from a date:
Calculate the difference in days between two dates:
(3) Case
Let's first create a birthday table:
We then insert the data into the table with the current date as the birthday.
2. String functions
(1) Overview
(2) Example
Get the character set of the name of the exam_result table.
It is required to display the information in the exam_result table, and the display format is: "XXX has XXX points in Chinese, and XXX points in mathematics."
Replace all names with "Tang" in the exam_result table with "Beijing".
3. Mathematical functions
(1) Overview
(2) Example
Take the absolute value.
Rounded up.
Round down.
Keep 2 decimal places (decimals are rounded)
Generate random numbers