频道栏目
首页 > 资讯 > MySQL > 正文

mysql必知必会读书笔记(三到九章)

17-04-26        来源:[db:作者]  
收藏   我要投稿

第三章使用:mysql

use database;//选择数据库
show databases;//查看所有数据库
show tables;//查看所有表
show columns from table_name;//查看表的所有列
show status;//显示服务器状态
show create database/table test;//查看创建数据库/表的命令
show grants;//查看授权用户的安全权限
show errors/warnings;//查看错误/警告信息

第四章:检索数据

select age,name from user;//从用户表查询年龄,姓名
select distinct age from user;//从用户表查询年龄(只返回年龄不同的值)
select (user.)age from user limit 5//从用户表查询年龄(只显示5行);
select age from user limit 5,5//从用户表查询年龄(从行5开始的5行);

第五章:排序检索数据

select age from user order by age;//按年龄排序显示用户表的年龄(默认的升序)
select age,height from user order by age,height;//按年龄和身高排序显示用户表的年龄,身高(仅当年龄相同时才会按照身高排序)
select age from user order by age desc;//按年龄排序显示用户表的年龄(降序排列,对多个列降序,必须对每一列都指定desc)

第六章:过滤数据

select age,name from user where age = 20;//显示年龄等于20的用户年龄和姓名(order by 应该放在where的后面)
select age,name from user where age between 10 and 20;//显示年龄大于等于10,小于等于20的用户年龄和姓名
用is 和 is not检查是否为空值(NULL)

第七章:数据过滤

select age,name from user where age < 20 and age > 10;//显示年龄在10到20之间的用户姓名和年龄
select age,name from user where age < 10 or age > 20;//显示年龄小于10或者大于20的用户姓名和年龄
select age,name from user where age (not) in (10,20);//显示年龄(不)等于10或者20的用户姓名和年龄

第八章:用通配符过滤

select name from user where name like ‘jot%’;//显示姓名以’jot’开头的姓名
select name from user where name like ‘at’;//显示姓名为_at’的姓名(只匹配一个字符,可以匹配hat,cat,fat…)

第九章:用正则表达式进行搜索

select name from user where name regexp ‘at’;//显示姓名中包含’at’的姓名(like是完全匹配,正则表达式是包含思想)
mysql正则表达式(常用的):
[:alnum:] :任意字母和数字
[:alpha:] :任意字母
[:digit:] :任意数字

相关TAG标签
上一篇:oracle之PLSQL优化查询语句——多种函数配合over()函数运用
下一篇:swustoj蛇形填数(1183)
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站