mysql基本语法

select *from db_user where user_type in(5,8);
select *from db_user where user_type between(5,8);
select *from db_user where user_name like '%s%';其中"%"可以匹配一个或多个字符
select *from db_user where user_name like '_3_';“_”匹配一个字符
select *from db_user where user_name=a or password=3;//or关键字,匹配一个就行
select *from db_user order by id desc;
select *from db_user order by id asc;//升序
select id,user_name,password group by user_type;//每组只显示一条记录
select *from db_user order by id asc limit 3;//限制只显示三条记录
select *from db_user order by id asc limit 1,2.从编号一开始,查询两条记录
select count(*) from db_user;//显示所有行的数目
select *from user_name ,user_type from tp_user,db_user here tp_user.id = db_user.id;//内连接查询,连接两个表
select *from tp_user where user_name in(select user_name from db_user);//查询tp_user中与db_user的user_name相同的记录
select *from tp_user where money >=(select money from db_user where id=1);//比较运算符的查询方式
select *from tp_user where user_name like '%php%';//查询包含php字段的记录
select Max(score) from tp_user;//查询socre最高的记录 
select *from tp_user where money<ANY(select money from db_user);//查询money小于所有db_user的记录,其中括号里的部分称为内查询,外面的称外查询
select *from tp_user where money>ALL(select money from db_user);//money大于所有的db_user
select user_name from tp_user UNION select user_name from db_user;//合并重复的user_name
select user_name from tp_user UNION ALL select user_name from db_user;//列出所有的结果,不合并\
//正则表达式
select books from tp_book where books REGEXP '^php' //^ 匹配以特定开头或字符串开头的记录
select books from tp_book where books REGEXP 'php$';//$匹配以特定结尾的记录
select books from tp_book where books REGEXP '.p';//.匹配字符集和中任意一个字符,包括换行和回车
select books from tp_book where books REGEXP '[pca]';//[pca]匹配包含pca的记录
select books from tp_book where books REGEXP '[^c-z]';//[^]匹配除字符集合以外的任何一个字符
select books from tp_book where books REGEXP 'php|java|c#';//|相当于or匹配任意一个字符串
select books from tp_book where books REGEXP 'J*A';//匹配A之前出现过J字符的记录,*可以表示0个
select books from tp_book where books REGEXP 'J+A';//匹配A之前至少出现过一次J的记录,+至少表示1个
select books from tp_book where books REGEXP 'a{3}';//匹配a出现至少三次的记录
select books from tp_book where books REGEXP 'a{2,4};//匹配a字符至少出现2次至多出现4次的记录


 

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值