您的位置:首页 > 数据库

SQL----函数

2015-12-02 10:29 288 查看
在看script的时候,经常会发现一些看不懂的地方。搜索了一下,发现sql还有很多的函数,这是以前不了解的。在这里做一个练习跟总结

--------|length()
返回字符串的长度
select  length(alliance_id)  from  application;


--------|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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: