专业编程基础技术教程

网站首页 > 基础教程 正文

sql 常用函数 统计函数

ccvgpt 2024-08-07 18:37:12 基础教程 8 ℃

入门级的统计函数:


(1)统计记录数 count函数

sql 常用函数 统计函数

可以统计出这条sql会查询出多少条记录很多人用count(*),但建议用count(1)


(2)求和函数 sum

select SUM(num) from tmp_p

对表中 num列进行求和


(3)求平均值

select AVG(num) from tmp_p

对表中 sum列进行求平均值.


(4)取出最大值

select MAX(num) from tmp_P

取出,num列中最大的一个


(5)取出最小值

select MIN(num) from tmp_P

取出,num列中最小的一个


(6)将数值型数据转换成字符型

select CONVERT(varchar(10),num) from tmp_p

该函数属于sql server的函数,其它数据库可参考相关资料


Tags:

最近发表
标签列表