- SQL函数
- AVG
select AVG(col) AS avgvalue from tablename
select col2 from tablename where col1>(select AVG(col1) from tablename) - COUNT 返回值不包含空值
select COUNT(*) from tablename 返回行数
select COUNT(DISTINCT col) from tablename 返回列的唯一值 - FIRST 返回第一个值
select FIRST(col) AS colname from tablename - LAST 返回最后一个值
select LAST(col) AS colname from tablename - MAX 返回最大值
- MIN 返回最小值
- SUM 返回总和
- GROUP BY
select col1, sum(col2) from tablename GROUP BY col1 - HAVING
select custom, sum(price) from tablename where custom = ‘tom‘ or custom = ‘jerry‘ group by custom HAVING sum(price)>1000 - UCASE 将字符转化为大写
select UCASE(col) from tablename - LCASE 将字符转为小写
- MID 提取字符
select MID(col, 起始数字, 长度) from tablename - LEN 提取字符长度
- ROUND 舍入指定位数
select ROUND(col, 位数) from tablename - NOW 返回当前时间和日期
select NOW() from tablename - FORMAT
select FORMAT(now(), ‘YYYY-MM-DD‘) from tablename
SQL学习笔记:函数
Posted 嘻呵呵
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL学习笔记:函数相关的知识,希望对你有一定的参考价值。
以上是关于SQL学习笔记:函数的主要内容,如果未能解决你的问题,请参考以下文章