【MySQL复习】日期函数和聚合函数

一、日期函数

1、curdate():获取当前日期

select curdate();

2、curtime():获取当前时间

3、now() :获取当前日期和时间

4、datediff(d1,d2):获取从d2 到d1 的天数

select datediff('2020-2-1','2020-1-1');

5、adddate(d1,n): 在d1日期累加n天

select adddate('2020-1-1',342);

6、subdate(d1,n) :在d1日期之前n 天

 

 

二、聚合函数

1、count(id) : 根据某个字段统计总记录数

select count(num) from tableName where ...;

2、sum() : 计算某个字段的总和

select sum(score) from tableName where ...;

3、avg() :求某个字段的平均值

select avg(score) from tableName where ...;

4、max() :求某个字段的最大值

5、min()  :求某个字段的最小值

 

三、条件查询

group by name 分组查询
order by score asc 升序查询(默认)
order by score desc 降序查询
posted @ 2022-02-24 11:51  小李不背锅  阅读(191)  评论(0)    收藏  举报