圣凤凌霜 发表于 2018-10-22 09:30:11

SQL----函数

  在看script的时候,经常会发现一些看不懂的地方。搜索了一下,发现sql还有很多的函数,这是以前不了解的。在这里做一个练习跟总结
  --------|length()
  返回字符串的长度
    selectlength(alliance_id)fromapplication;  --------|substr(string,start,count)
  取子字符串,从start开始,取出count个字符
    select substr(application_receipt_date,2,3)from application;  -------|replace(string,s1,s2)
  string 希望被替换掉的字符或者变量
  s1:被替换的字符
  s2:要替换的字符
   select replace(application_receipt_date,'JUN','otc')from application;  --------|add_months()
  增加或者删减月份
  -------|last_day
  返回日期的最后一天
  -------|months_between(date2,date1)
  返回date2-date1之间的月份
  -------|to_char , TO_MULTI_BYTE , TO_NUMBER
select to_char(application_receipt_date,'mm.dd')from application;  ------|sysdate
  返回系统时间
  ------|LEAST , min() ,max()
  返回一组表达式中最 大/小 的值
  -------|UID
  返回当前用户的唯一整数
  ------|AVG(distinct|all)
  all 对于所有的值求平均值
  distinct 只对不同的值求平均值
  ------|group by
  主要对于一组数做统计
select application_id,count(*) from application group by application_id;  表示从这个表中选取application 并且统计出现的总数。
  ------|having
  对于分组统计再加上限制条件,类似where
  ------|order by.... desc
  对于查询结果进行排序。
  desc属于降序排序
  更多函数可参考:
  http://www.cnblogs.com/zhangronghua/archive/2007/08/20/862812.html


页: [1]
查看完整版本: SQL----函数