mysql中常用的函数
来源:互联网 发布:淘宝怎么写评论 编辑:程序博客网 时间:2024/05/16 15:36
总结一下,自己经常会使用到的mysql 函数,与大家分享
1)字符串连接函数 concat(str1,str2,str2...)
2)提取子串函数 substring(str,start,len)
其中,若省略len 则是从start开始到字串结束
若省略len,且start为负数,则是从字符串末尾往前提取|start|个字符
select c.id,c.fullname,u.id uid, concat(u.lastname,u.firstname) as author, u.department as dept,c.summary,ct.id as fid,f.filenamefrom mdl_course cleft join mdl_log lgon substring(lg.url,13) = c.id and lg.action = 'new'left join mdl_user uon lg.userid = u.idleft join mdl_context cton ct.instanceid = c.id and ct.contextlevel = 50left join mdl_files fon f.contextid = ct.id and f.filename !='.'ORDER BY c.timemodified desc limit 8";3)去重函数 distinct(field)
select distinct(name) from usergrade
4)求和函数 sum(field)
使用求和函数时,一般会使用group by 进行分组
select sum(grade) ,username from usergrade group by classid
5)统计函数 count(field) 这个太常见,一般使用PHP自带count就可以实现
6)生成md5 加密函数 md5(str)
select md5('123456')
暂时就写这么多,用到了再加上来。
2014-09-28 补充函数:
7)连接查询结果函数 group_concat(field) 默认以','分割
8)正则表达式过滤函数 regexp '正则表达式'
这个非常强大,要了解正则相关知识
select group_concat(id) ids from mdl_course_categories where path regexp '/3/' or id=39)查询子串是否存在 INSTR(str,substr)
或者substring_index(str,substr, offset) 两者都非常强大
在无限级分类的path路径寻找中非常有用
select c.id, c.fullname, c.startdate, substr(substring_index(path, '/', 2) , 2) as topcateidfrom mdl_course cleft join mdl_course_categories cc on c.category=cc.id
0 0
- MYSQL中常用的函数
- mysql中常用的函数
- mysql中常用函数
- MySQL中常用的内置系统函数
- mysql中常用的字符串函数
- MYSQL中string的常用函数
- 项目中常用的mysql函数
- Mysql中常用的函数汇总
- mysql 中一些常用的函数
- MYSQL中常用的字符串函数
- MySql常用的函数
- mysql的常用函数
- mysql的常用函数
- mysql的常用函数
- mysql常用的函数
- mysql的常用函数
- MYSQL的常用函数
- MySQL常用的函数
- 算法与追mm:算法导论之SSM PKU版
- 各种检索的关系
- vmware安装opensuse
- cocos2d-x ccsprite 使用 shader生成自己想要的颜色的图片
- ffmpeg AV_SAMPLE_FMT_FLTP to AV_SAMPLE_FMT_S16
- mysql中常用的函数
- spring的RabbitTemplate 接收Message源码导读
- 连载《一个程序员的成长历程》-11.80后结婚,房子是悬在每个人心中的一块石头
- Annotation 使用笔记(二) 注解生成SQL脚本
- A program to check if a binary tree is BST or not
- Linux磁盘分区
- POJ 3281 Dining
- 简单的模态对话框ModalDialog -- 源码分享
- 函数与链表