[MySQL learning articles]-aggregate functions and commonly used functions
Article Directory
Aggregate function
In MySQL, the function is called using the select keyword: select function name (field name) from table name
Maximum value: max (field name)
Minimum value: min (field name)
SELECT MAX(score) FROM users;
SELECT MIN(score) as 最低分 FROM users;
Find the average: avg (field name)
SELECT AVG(score) AS 平均分 FROM users;
Sum: sum (field name)
SELECT SUM(score) AS 总分数 FROM users;
Statistics record
SELECT COUNT(*) FROM users;#统计表中所有非空字段总条数
SELECT COUNT(phone) FROM users;#统计该字段有多少条数据非空
Commonly used functions
Time function
# now():获取当前系统时间,包括年月日时分秒
SELECT NOW() AS 当前时间;
#curtime() :获取系统的时分秒
SELECT CURTIME();
#curdate() : 获取系统的年月日
SELECT CURDATE();
Mathematical function
#向上取整:ceil()
SELECT CEIL(2.2);
#向下取整:floor()
SELECT FLOOR(2.2);
#返回随机数(0,1)rand()
SELECT RAND();