常用函数总结

来源:未知 责任编辑:责任编辑 发表时间:2013-11-18 20:57 点击:

聚合函数
avg(): 函数返回组中各值的平均数
sum():函数返回组中各值之和
1
select sum(money) from cash
count():函数返回匹配指定条件的行数
count(column_name) 函数返回指定列的值的数目(NULL 不计入)
count(*) 函数返回表中的记录数
count(DISTINCT column_name) 函数返回指定列的不同值的数目
   www.2cto.com  
查询范围——orders表:
 
O_IdOrderDateOrderPriceCustomer
1 2008/12/29 1000 Bush
2 2008/11/23 1600 Carter
3 2008/10/05 700 Bush
4 2008/09/28 300 Bush
5 2008/08/06 2000 Adams
6 2008/07/21 100 Carter
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
select count(*) N'Bush的订单总数' from orders
where cumstomer = 'Bush'
 
执行结果:3
 
select count(customer) from orders
where OrderPrice >= 1000
 
执行结果:3
 
select count(distinct customer) from orders
where OrderPrice <= 1000
 
执行结果:2
Max():函数返回表达式的最大值
Min():函数返回表达式的最小值
 
日期函数
getdate():函数返回当前时间
1
2
3
select getdate()
   www.2cto.com  
函数返回:2012-04-09 21:29:25.493
datepart(datepart, date):函数返回时间的某一部分
datepart的有效值如下:
datepart缩写
yy, yyyy
季度 qq, q
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Request.ServerVariables 参数大全
  • 执行全文索引时出现权限不足的解决方法
  • 导入excel文件处理流程节点的解决方案
  • 查看sql修改痕迹(SQL Change Tracking on Table)
  • App数据层设计及云存储使用指南
  • PostgreSQL启动过程中的那些事三:加载GUC参数
  • MongoDB安装为Windows服务方法与注意事项
  • Percolator与分布式事务思考(二)
  • 写给MongoDB开发者的50条建议Tip1
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1