函数sql语句

上一篇 / 下一篇  2014-07-21 17:33:25 / 个人分类:数据库


                                                   /*字符串函数*/

--返回字符串中从左边或右边开始指定个数的字符
 
select left('abcd',2) 
select right('abcd',2)
--返回指定字符串表达式的字符数,其中不包含尾随空格
 
select len('ab cd  ') 
--返回替换后新的字符串
select replace('aaabbbccc','aaa','111')
 
--把ASCII 码转换为字符,介于 0 和 255 之间的整数,否则返回null值
select char(97)
--(float型小数,总长度,小数点后保留的位数),注意在截断时四舍五入 
  
select str(123.156,5,1)
 
                                         /*日期和时间函数*/
--返回当前系统日期时间
select getdate()
--返回指定日期的部分(日月年)
select day('2013-09-12')
select month('2013-09-12')
select year('2013-09-12')
--返回指定日期的部分(这年的第几天dy、一星期中星期几wk、一年第几星期)dw(默认1为星期天)
select datepart(wk,'2014-06-12')
select datepart(dw,'2014-06-12')
select datepart(dy,'2014-06-12')

--返回给指定日期加上一个时间间隔后的新的日期值
select dateadd(year,30,'2014-12-10')
select dateadd(month,10,'2014-12-12')
select dateadd(hour,12,'1990-12-11')
--返回两个指定日期的指定日期部分的差的整数值
select datediff(year,'2014-12-12','2000-12-12')
select datediff(month,'2014-12-12','2000-12-12')
select datediff(day,'2014-12-12','2000-12-12')

                                          /*数学函数*/
--返回指定数值表达式的绝对值
  
   select abs(-123)
--返回大于或等于指定数值表达式的最小整数
 
 select ceiling(5.33)
 select ceiling(-7.23)
--返回小于或等于指定数值表达式的最大整数
 select floor(5.33)
 select floor(-7.23)
 
--返回数值表达式1的数值表达式2次幂
 select power(3,3)
--返回数值表达式的平方根
 select sqrt(28)
                                            /*聚合函数*/
  
--返回组中各值的平均值,空值将被忽略
  
     select avg(age)as '平均分' from student
  
--返回组的项数。COUNT(*) 返回组中的项数。包括 NULL 值和重复项。如果指定表达式则忽略空值
     select count(*)from student
     select count(age)from student
     select count(distinct age)from student
    
--返回组中值的最小值,空值将被忽略
      select min(age)from student
   
--返回组中值的最大值,空值将被忽略
      select max(age)from student
     
--返回组中值的和,空值将被忽略
      select sum(age) as '总年龄'from student
     

TAG:

 

评分:0

我来说两句

Open Toolbar