The second day to learn MySQL
2016-10-20 00:19
381 查看
MySQL图形化工具 Navicat 数据操作语言 Create table 表名: 创建表 Insert into 表名(列名1, 列名2, 列名3...)values(列名1值,列名2值, 列名3值.) :新增值 Delete from 表名 : 删除表 Update 表名 set 列名1=修改的值,列名2=修改的值; :修改值 Select * from 表名 :查询整个表 Select * from 表名 where 列名1=值 and 列名2=值.... :根据条件查询指定的数据 Select 列名1,列名2 from :查询指定的列的数据 Select 列名 (as)别名,列名2 (as)别名2... from 表名; : 给指定返回列取别名(as)表示可有可无
SELECT * FROM 表名 where 字段 > < >= <= !=或<> :在条件中使用运算符 and or not (和,或者,不) ag:select * from student where age<=21 and sex='女' (在表student中查询年龄小于等于21岁的女生)。 ag:select * from student where age<=21 or sex='女' (在表student中查询年龄小于等于21岁的学生或女生) (二者都会被查询出来)。 对空值的查询:is null 对应列是否null查询 select * from 表名 where 对应列 is not null select * from 表名 where 列名 BETWEEN A and B; 查询表中对应列A和B之间的值(包含A和B的值)。 select * from 表名 where 列名 in(a,b,c); 查询表中对应列满足a、b、c中任一一个的值。 模糊查询 like _:指代明确值的位置或已知字符串长度 %:指代不明确值的位置或长度 select * from 表名 where 列名 like '_A%'; 查询表中对应列第二个字为A的值。 select * from 表名 where 列名 like 'A_%'; 查询表中对应列第一个字为A的值。 select * from 表名 where 列名 like '%A%'; 查询表中对应列含有A的值。 查询中使用算术表达式:+ - * / :在表中对相应列进行运算。 处理重复值:DISTINCT 排除重复展示,只展示一次 select DISTINCT sex from 表名; 只展示一次表中的性别。 select * from 表名 limit 10; 查询数据的前10位 select * from 表名 limit 10,10; 查询表中第11至第20位的数据 (有多少数据显示多少数据,直到第20个) create table 目标表名 select*from 现有表名; 把现有表复制到目标表中。 create table 目标表名 select*from where flase; 只复制表的结构。(flase如1=2,当条件不满足时,不复制值) select * from 表名 order by :升序排序(默认) select * from 表名 order by desc 将需拍下
常用函数 得到需要查询字符的ascii码 select ascii('字符'); 根据字符集查询得到的字符的长度 select char_length('字符'); 拼接字符串 select concat ('字符1','字符2','字符3'......); 大写转小写 select lower('ABC'); 小写转大写 select upper('abc'); 查询表中对应列的对应数据的最后一个字 select right(对应列,1) from 表名; 查询表中对应列的对应数据的第一个字 select left(对应列,1) from 表名;
聚合函数: COUNT 统计数量:select count(列名) from 表名;SUM 求和:select sum(列名) from 表名;MAX 求最大值:select max(列名) from 表名;MIN 求最小值:select min(列名) from 表名;AVG 平均数:select avg(列名) from 表名;
SELECT * FROM 表名 where 字段 > < >= <= !=或<> :在条件中使用运算符 and or not (和,或者,不) ag:select * from student where age<=21 and sex='女' (在表student中查询年龄小于等于21岁的女生)。 ag:select * from student where age<=21 or sex='女' (在表student中查询年龄小于等于21岁的学生或女生) (二者都会被查询出来)。 对空值的查询:is null 对应列是否null查询 select * from 表名 where 对应列 is not null select * from 表名 where 列名 BETWEEN A and B; 查询表中对应列A和B之间的值(包含A和B的值)。 select * from 表名 where 列名 in(a,b,c); 查询表中对应列满足a、b、c中任一一个的值。 模糊查询 like _:指代明确值的位置或已知字符串长度 %:指代不明确值的位置或长度 select * from 表名 where 列名 like '_A%'; 查询表中对应列第二个字为A的值。 select * from 表名 where 列名 like 'A_%'; 查询表中对应列第一个字为A的值。 select * from 表名 where 列名 like '%A%'; 查询表中对应列含有A的值。 查询中使用算术表达式:+ - * / :在表中对相应列进行运算。 处理重复值:DISTINCT 排除重复展示,只展示一次 select DISTINCT sex from 表名; 只展示一次表中的性别。 select * from 表名 limit 10; 查询数据的前10位 select * from 表名 limit 10,10; 查询表中第11至第20位的数据 (有多少数据显示多少数据,直到第20个) create table 目标表名 select*from 现有表名; 把现有表复制到目标表中。 create table 目标表名 select*from where flase; 只复制表的结构。(flase如1=2,当条件不满足时,不复制值) select * from 表名 order by :升序排序(默认) select * from 表名 order by desc 将需拍下
常用函数 得到需要查询字符的ascii码 select ascii('字符'); 根据字符集查询得到的字符的长度 select char_length('字符'); 拼接字符串 select concat ('字符1','字符2','字符3'......); 大写转小写 select lower('ABC'); 小写转大写 select upper('abc'); 查询表中对应列的对应数据的最后一个字 select right(对应列,1) from 表名; 查询表中对应列的对应数据的第一个字 select left(对应列,1) from 表名;
聚合函数: COUNT 统计数量:select count(列名) from 表名;SUM 求和:select sum(列名) from 表名;MAX 求最大值:select max(列名) from 表名;MIN 求最小值:select min(列名) from 表名;AVG 平均数:select avg(列名) from 表名;
相关文章推荐
- The first day to learn Android
- Tips: How to resolve the issue of MySQL about abnormal login after system launched.
- Input — the only way to learn English
- The JFC Swing Tutorial: A Guide to Constructing GUIs, Second Edition
- the best way to learn things is Just to do it.
- The Definitive Guide to Grails, Second Edition
- Code snippet of the day : Exporting DataGrid Data to Excel...
- AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Second Edition
- The Data Warehouse Toolkit: The Complete Guide to Dimensional Modeling (Second Edition)
- The Definitive Guide to SOA: Oracle® Service Bus, Second Edition
- how to initialize the vp for second time
- The Definitive Guide To MySQL - 阅读手记
- to learn living in the present time(06年11月)
- Moving to Linux, Second Edition: Kiss the Blue Screen of Death Goodbye! (2nd Edition)
- The way to learn English
- The Definitive Guide To MySQL - 阅读手记2
- Day 3: The Number One Secret To Speaking English
- 学语言最好的方法是尽量多地联系使用它。(The way to learn a language is to practice using it as often as possible.)
- The 'InnoDB' feature is disabled; you need MySQL built with 'InnoDB' to have it working处理方法
- java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for