文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>sql的函数列举

sql的函数列举

时间:2010-08-19  来源:icybay

sql函数的语法:select function(列) from 表
分为aggregate函数(针对多值操作)和scalar函数(针对单值操作)。
如果select语句中有select语句嵌套,则必须使用group by

avg():

SELECT AVG(column_name) FROM table_name


count():

SELECT COUNT(column_name) FROM table_name  --or (distinct column_name)


first() or last():

SELECT FIRST(column_name) FROM table_name
SELECT LAST(column_name) FROM table_name


max() or min() or sum():

SELECT MAX(column_name) FROM table_name
SELECT MIN(column_name) FROM table_name
SELECT SUM(column_name) FROM table_name


group by:

SELECT column_name, aggregate_function(column_name) FROM table_name
WHERE column_name operator value GROUP BY column_name --按某个列名进行操作


having:

SELECT column_name, aggregate_function(column_name) FROM table_name
WHERE column_name operator value GROUP BY column_name HAVING aggregate_function(column_name) operator value

for example
SELECT Customer,SUM(OrderPrice) FROM Orders WHERE Customer='Bush' OR Customer='Adams' GROUP BY Customer HAVING SUM(OrderPrice)>1500


ucase() or lcase():

SELECT UCASE(column_name) FROM table_name
SELECT LCASE(column_name) FROM table_name


mid() or len():

SELECT MID(column_name,start[,length]) FROM table_name --mid:提取字符

 SELECT LEN(column_name) FROM table_name --len:返回文本长度

round():

SELECT ROUND(column,decimals) FROM table_name --:decimals:小数位,四舍五入
SELECT ProductName, ROUND(UnitPrice,0) as UnitPrice FROM Products


now():

SELECT NOW() FROM table_name  --显示当前时间


format():

SELECT FORMAT(column_name,format) FROM table_name

SELECT ProductName, UnitPrice, FORMAT(Now(),'YYYY-MM-DD') as PerDate
FROM Products


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载