1. 昨日回顾
  2. 表与表之间建关系
  3. 一对多
  4. 换位思考
  5. 图书与出版社
  6. 先站在左表:
  7. 考虑左表的多条数据能否对应右表的一条数据
  8. 翻译:多本书能否被一个出版社出版 可以!
  9. 注意:单站在一张得出的表关系并不能明确两张表之间真正关系!!!
  10. 再站在右表:
  11. 考虑右表的多条数据能否对应左表的一条数据
  12. 翻译:多个出版社能否出版一本书 不可以!
  13. 通常一对多的外键字段建立在多的那一方
  14. 外键约束:
  15. 1.必须先创建被关联表
  16. 2.插入数据的时候必选先插入被关联表
  17. 3.新增同步更新同步删除功能
  18. create table publish(
  19. id int primary key auto_increment,
  20. title char(16)
  21. )
  22. create table book(
  23. id int primary key auto_increment,
  24. title char(16),
  25. price int,
  26. publish_id int,
  27. foreign key(publish_id) references publish(id)
  28. on update cascade
  29. on delete cascade
  30. )
  31. 多对多
  32. 图书与作者
  33. 一本书可不可以有多个作者 可以!
  34. 一个作者可不可以写多本书 可以!
  35. 多对多
  36. create table book(
  37. id int primary key auto_increment,
  38. title char(16),
  39. price int
  40. );
  41. create table author(
  42. id int primary key auto_increment,
  43. name char(16),
  44. gender char(6)
  45. );
  46. create table book2author(
  47. id int primary key auto_increment,
  48. book_id int,
  49. author_id int,
  50. foreign key(book_id) references book(id)
  51. on update cascade
  52. on delete cascade,
  53. foreign key(author_id) references author(id)
  54. on update cascade
  55. on delete cascade
  56. );
  57. 一对一
  58. 客户与学生:一对一
  59. 用户与用户详情:
  60. user fk
  61. id name pwd userdetail_id
  62. 1 egon 123 1
  63. 2 tank 123 2
  64. 3 jason 123 3
  65. userdetail
  66. id phone addr is_dog hobby
  67. 1 110 7 1 喊麦
  68. 2 120 楼下 1 生蚝
  69. 3 130 楼上 1 学习
  70. mysql忽略大小写
  71. 修改表
  72. alter table t1 modify name char(6)
  73. alter table t1 change name new_name char(16) not null default 'xxx'
  74. 复制表
  75. create table t1 select * from test;
  76. 只复制表结构
  77. create table t1 select * from test where 1=2;

单表查询

前期表准备

  1. create table emp(
  2. id int not null unique auto_increment,
  3. name varchar(20) not null,
  4. sex enum('male','female') not null default 'male', #大部分是男的
  5. age int(3) unsigned not null default 28,
  6. hire_date date not null,
  7. post varchar(50),
  8. post_comment varchar(100),
  9. salary double(15,2),
  10. office int, #一个部门一个屋子
  11. depart_id int
  12. );
  13. #插入记录
  14. #三个部门:教学,销售,运营
  15. insert into emp(name,sex,age,hire_date,post,salary,office,depart_id) values
  16. ('jason','male',18,'20170301','张江第一帅形象代言',7300.33,401,1), #以下是教学部
  17. ('egon','male',78,'20150302','teacher',1000000.31,401,1),
  18. ('kevin','male',81,'20130305','teacher',8300,401,1),
  19. ('tank','male',73,'20140701','teacher',3500,401,1),
  20. ('owen','male',28,'20121101','teacher',2100,401,1),
  21. ('jerry','female',18,'20110211','teacher',9000,401,1),
  22. ('nick','male',18,'19000301','teacher',30000,401,1),
  23. ('sean','male',48,'20101111','teacher',10000,401,1),
  24. ('歪歪','female',48,'20150311','sale',3000.13,402,2),#以下是销售部门
  25. ('丫丫','female',38,'20101101','sale',2000.35,402,2),
  26. ('丁丁','female',18,'20110312','sale',1000.37,402,2),
  27. ('星星','female',18,'20160513','sale',3000.29,402,2),
  28. ('格格','female',28,'20170127','sale',4000.33,402,2),
  29. ('张野','male',28,'20160311','operation',10000.13,403,3), #以下是运营部门
  30. ('程咬金','male',18,'19970312','operation',20000,403,3),
  31. ('程咬银','female',18,'20130311','operation',19000,403,3),
  32. ('程咬铜','male',18,'20150411','operation',18000,403,3),
  33. ('程咬铁','female',18,'20140512','operation',17000,403,3)
  34. ;
  35. #ps:如果在windows系统中,插入中文字符,select的结果为空白,可以将所有字符编码统一设置成gbk

1.语法执行顺序

  1. # 初识查询语句
  2. select id,name from emp where id >= 3 and id <= 6;
  3. # 先后顺序
  4. from
  5. where
  6. select

2.where约束条件

  1. # 1.查询id大于等于3小于等于6的数据
  2. select id,name from emp where id >= 3 and id <= 6;
  3. select * from emp where id between 3 and 6;
  4. # 2.查询薪资是20000或者18000或者17000的数据
  5. select * from emp where salary = 20000 or salary = 18000 or salary = 17000;
  6. select * from emp where salary in (20000,18000,17000); # 简写
  7. # 3.查询员工姓名中包含o字母的员工姓名和薪资
  8. # 在你刚开始接触mysql查询的时候,建议你按照查询的优先级顺序拼写出你的sql语句
  9. """
  10. 先是查哪张表 from emp
  11. 再是根据什么条件去查 where name like ‘%o%’
  12. 再是对查询出来的数据筛选展示部分 select name,salary
  13. """
  14. select name,salary from emp where name like '%o%';
  15. # 4.查询员工姓名是由四个字符组成的员工姓名与其薪资
  16. select name,salary from emp where name like '____';
  17. select name,salary from emp where char_length(name) = 4;
  18. # 5.查询id小于3或者大于6的数据
  19. select * from emp where id not between 3 and 6;
  20. # 6.查询薪资不在20000,18000,17000范围的数据
  21. select * from emp where salary not in (20000,18000,17000);
  22. # 7.查询岗位描述为空的员工名与岗位名 针对null不能用等号,只能用is
  23. select name,post from emp where post_comment = NULL; # 查询为空!
  24. select name,post from emp where post_comment is NULL;
  25. select name,post from emp where post_comment is not NULL;

3.group by

  1. # 数据分组应用场景:每个部门的平均薪资,男女比例等
  2. # 1.按部门分组
  3. select * from emp group by post; # 分组后取出的是每个组的第一条数据
  4. select id,name,sex from emp group by post; # 验证
  5. """
  6. 设置sql_mode为only_full_group_by,意味着以后但凡分组,只能取到分组的依据,
  7. 不应该在去取组里面的单个元素的值,那样的话分组就没有意义了,因为不分组就是对单个元素信息的随意获取
  8. """
  9. set global sql_mode="strict_trans_tables,only_full_group_by";
  10. # 重新链接客户端
  11. select * from emp group by post; # 报错
  12. select id,name,sex from emp group by post; # 报错
  13. select post from emp group by post; # 获取部门信息
  14. # 强调:只要分组了,就不能够再“直接”查找到单个数据信息了,只能获取到组名
  15. # 2.获取每个部门的最高工资
  16. # 以组为单位统计组内数据>>>聚合查询(聚集到一起合成为一个结果)
  17. # 每个部门的最高工资
  18. select post,max(salary) from emp group by post;
  19. # 每个部门的最低工资
  20. select post,min(salary) from emp group by post;
  21. # 每个部门的平均工资
  22. select post,avg(salary) from emp group by post;
  23. # 每个部门的工资总和
  24. select post,sum(salary) from emp group by post;
  25. # 每个部门的人数
  26. select post,count(id) from emp group by post;
  27. # 3.查询分组之后的部门名称和每个部门下所有的学生姓名
  28. # group_concat(分组之后用)不仅可以用来显示除分组外字段还有拼接字符串的作用
  29. select post,group_concat(name) from emp group by post;
  30. select post,group_concat(name,"_SB") from emp group by post;
  31. select post,group_concat(name,": ",salary) from emp group by post;
  32. select post,group_concat(salary) from emp group by post;
  33. # 4.补充concat(不分组时用)拼接字符串达到更好的显示效果 as语法使用
  34. select name as 姓名,salary as 薪资 from emp;
  35. select concat("NAME: ",name) as 姓名,concat("SAL: ",salary) as 薪资 from emp;
  36. # 补充as语法 即可以给字段起别名也可以给表起
  37. select emp.id,emp.name from emp as t1; # 报错 因为表名已经被你改成了t1
  38. select t1.id,t1.name from emp as t1;
  39. # 查询四则运算
  40. # 查询每个人的年薪
  41. select name,salary*12 as annual_salary from emp;
  42. select name,salary*12 annual_salary from emp; # as可以省略

练习题

  1. # 刚开始查询表,一定要按照最基本的步骤,先确定是哪张表,再确定查这张表也没有限制条件,再确定是否需要分类,最后再确定需要什么字段对应的信息
  2. 1. 查询岗位名以及岗位包含的所有员工名字
  3. 2. 查询岗位名以及各岗位内包含的员工个数
  4. 3. 查询公司内男员工和女员工的个数
  5. 4. 查询岗位名以及各岗位的平均薪资
  6. 5. 查询岗位名以及各岗位的最高薪资
  7. 6. 查询岗位名以及各岗位的最低薪资
  8. 7. 查询男员工与男员工的平均薪资,女员工与女员工的平均薪资
  9. """
  10. 参考答案:
  11. select post,group_concat(name) from emp group by post;
  12. select post,count(id) from emp group by post;
  13. select sex,count(id) from employee group by sex;
  14. select post,avg(salary) from emp group by post;
  15. select post,max(salary) from employee group by post;
  16. select post,min(salary) from employee group by post;
  17. select sex,avg(salary) from employee group by sex;
  18. """
  19. # 关键字where group by同时出现的情况下,group by必须在where之后
  20. # where先对整张表进行一次筛选,如何group by再对筛选过后的表进行分组
  21. # 如何验证where是在group by之前执行而不是之后 利用聚合函数 因为聚合函数只能在分组之后才能使用
  22. select id,name,age from emp where max(salary) > 3000; # 报错!
  23. select max(salary) from emp;
  24. # 正常运行,不分组意味着每一个人都是一组,等运行到max(salary)的时候已经经过where,group by操作了,只不过我们都没有写这些条件
  25. # 语法顺序
  26. select
  27. from
  28. where
  29. group by
  30. # 再识执行顺序
  31. from
  32. where
  33. group by
  34. select
  35. 8、统计各部门年龄在30岁以上的员工平均工资
  36. select post,avg(salary) from emp where age > 30 group by post;
  37. # 对where过滤出来的虚拟表进行一个分组
  38. # 还不明白可以分步执行查看结构
  39. select * from emp where age>30;
  40. # 基于上面的虚拟表进行分组
  41. select * from emp where age>=30 group by post;

4.having

截止目前已经学习的语法

  1. select 查询字段1,查询字段2,... from 表名
  2. where 过滤条件
  3. group by分组依据
  4. # 语法这么写,但是执行顺序却不一样
  5. from
  6. where
  7. group by
  8. select

having的语法格式与where一致,只不过having是在分组之后进行的过滤,即where虽然不能用聚合函数,但是having可以!

  1. 1、统计各部门年龄在30岁以上的员工平均工资,并且保留平均工资大于10000的部门
  2. select post,avg(salary) from emp
  3. where age >= 30
  4. group by post
  5. having avg(salary) > 10000;
  6. # 如果不信你可以将having取掉,查看结果,对比即可验证having用法!
  7. #强调:having必须在group by后面使用
  8. select * from emp having avg(salary) > 10000; # 报错

5.distinct

  1. # 对有重复的展示数据进行去重操作
  2. select distinct post from emp;

6.order by

  1. select * from emp order by salary asc; #默认升序排
  2. select * from emp order by salary desc; #降序排
  3. select * from emp order by age desc; #降序排
  4. #先按照age降序排,在年龄相同的情况下再按照薪资升序排
  5. select * from emp order by age desc,salary asc;
  6. # 统计各部门年龄在10岁以上的员工平均工资,并且保留平均工资大于1000的部门,然后对平均工资进行排序
  7. select post,avg(salary) from emp
  8. where age > 10
  9. group by post
  10. having avg(salary) > 1000
  11. order by avg(salary)
  12. ;

7.limit

  1. # 限制展示条数
  2. select * from emp limit 3;
  3. # 查询工资最高的人的详细信息
  4. select * from emp order by salary desc limit 1;
  5. # 分页显示
  6. select * from emp limit 0,5; # 第一个参数表示起始位置,第二个参数表示的是条数,不是索引位置
  7. select * from emp limit 5,5;

8.正则

  1. select * from emp where name regexp '^j.*(n|y)$';

多表查询

表创建

  1. #建表
  2. create table dep2(
  3. id int,
  4. name varchar(20)
  5. );
  6. create table emp2(
  7. id int primary key auto_increment,
  8. name varchar(20),
  9. sex enum('male','female') not null default 'male',
  10. age int,
  11. dep_id int
  12. );
  13. #插入数据
  14. insert into dep2 values
  15. (200,'技术'),
  16. (201,'人力资源'),
  17. (202,'销售'),
  18. (203,'运营');
  19. insert into emp2(name,sex,age,dep_id) values
  20. ('jason','male',18,200),
  21. ('egon','female',48,201),
  22. ('kevin','male',38,201),
  23. ('nick','female',28,202),
  24. ('owen','male',18,200),
  25. ('jerry','female',18,204)
  26. ;
  27. # 当初为什么我们要分表,就是为了方便管理,在硬盘上确实是多张表,但是到了内存中我们应该把他们再拼成一张表进行查询才合理

表查询

  1. select * from emp,dep; # 左表一条记录与右表所有记录都对应一遍>>>笛卡尔积
  2. # 将所有的数据都对应了一遍,虽然不合理但是其中有合理的数据,现在我们需要做的就是找出合理的数据
  3. # 查询员工及所在部门的信息
  4. select * from emp,dep where emp.dep_id = dep.id;
  5. # 查询部门为技术部的员工及部门信息
  6. select * from emp,dep where emp.dep_id = dep.id and dep.name = '技术';
  7. # 将两张表关联到一起的操作,有专门对应的方法
  8. # 1、内连接:只取两张表有对应关系的记录
  9. select * from emp inner join dep on emp.dep_id = dep.id;
  10. select * from emp inner join dep on emp.dep_id = dep.id
  11. where dep.name = "技术";
  12. # 2、左连接: 在内连接的基础上保留左表没有对应关系的记录
  13. select * from emp left join dep on emp.dep_id = dep.id;
  14. # 3、右连接: 在内连接的基础上保留右表没有对应关系的记录
  15. select * from emp right join dep on emp.dep_id = dep.id;
  16. # 4、全连接:在内连接的基础上保留左、右面表没有对应关系的的记录
  17. select * from emp left join dep on emp.dep_id = dep.id
  18. union
  19. select * from emp right join dep on emp.dep_id = dep.id;

子查询

  1. # 就是将一个查询语句的结果用括号括起来当作另外一个查询语句的条件去用
  2. # 1.查询部门是技术或者人力资源的员工信息
  3. """
  4. 先获取技术部和人力资源部的id号,再去员工表里面根据前面的id筛选出符合要求的员工信息
  5. """
  6. select * from emp where dep_id in (select id from dep where name = "技术" or name = "人力资源");
  7. # 2.每个部门最新入职的员工 思路:先查每个部门最新入职的员工,再按部门对应上联表查询
  8. select t1.id,t1.name,t1.hire_date,t1.post,t2.* from emp as t1
  9. inner join
  10. (select post,max(hire_date) as max_date from emp group by post) as t2
  11. on t1.post = t2.post
  12. where t1.hire_date = t2.max_date
  13. ;
  14. """
  15. 记住一个规律,表的查询结果可以作为其他表的查询条件,也可以通过其别名的方式把它作为一张虚拟表去跟其他表做关联查询
  16. """
  17. select * from emp inner join dep on emp.dep_id = dep.id;

补充单表查询

  1. 书写顺序
  2. select id,name from emp where id >3 and id <6;
  3. 执行顺序
  4. from # 先确定是哪张表
  5. where # 再确定是否有过滤条件
  6. select # 最后确定要过滤出来的数据的哪些字段
  7. select id,name from emp where id >3
  8. where查询
  9. # 1.查询id大于等于3小于等于6的数据
  10. select * from emp where id >= 3 and id <= 6;
  11. select id,name from emp where id between 3 and 6;
  12. # 2.查询薪资是20000或者18000或者17000的数据
  13. select * from emp where salary = 20000 or salary = 18000 or salary = 17000;
  14. select id,name from emp where salary in (20000,18000,17000);
  15. # 3.查询员工姓名中包含o字母的员工姓名和薪资
  16. select name,salary from emp where name like '%o%';
  17. # 4.查询员工姓名是由四个字符组成的员工姓名与其薪资
  18. select name,salary from emp where name like '____';
  19. select name,salary from emp where char_length(name) = 4;
  20. # 5.查询id小于3或者大于6的数据
  21. # 6.查询薪资不在20000,18000,17000范围的数据
  22. select id,name from emp where salary not in (20000,18000,17000);
  23. # 7.查询岗位描述为空的员工名与岗位名 判断空不能用等号只能用is
  24. select name,post from emp where post_comment = NULL;
  25. select name,post from emp where post_comment is NULL;
  26. group by分组
  27. # 1.按部门分组
  28. select * from emp group by post;
  29. # 分组之后只能获取到分组依据的字段值,不能直接获取到组内单个数据的信息
  30. # 设置严格模式
  31. set global sql_mode="strict_trans_tables,only_full_group_by";
  32. select * from emp group by post;
  33. select id,name from emp group by post;
  34. 聚合函数
  35. # 2.获取每个部门的最高工资
  36. select post,max(salary) from emp group by post;
  37. # 每个部门的最低工资
  38. select post,min(salary) from emp group by post;
  39. # 每个部门的平均工资
  40. select post,avg(salary) from emp group by post;
  41. # 每个部门的工资总和
  42. select post,sum(salary) from emp group by post;
  43. # 每个部门的人数
  44. select post,count(id) from emp group by post;
  45. select post,count(salary) from emp group by post;
  46. # 3.查询分组之后的部门名称和每个部门下所有的学生姓名
  47. group_concat()
  48. select post,group_concat(name) from emp group by post;
  49. select post,group_concat(name,'DSB') from emp group by post;
  50. as语法
  51. select post as '部门',group_concat(name,'DSB') as '员工姓名' from emp group by post;
  52. select post '部门',group_concat(name,'DSB') '员工姓名' from emp group by post;
  53. select emp.id,emp.name from emp;
  54. select t1.id,t1.name from emp as t1;
  55. select id,name from emp as t1;
  56. concat()
  57. select id,concat('NAME:',name) from emp where id <5;
  58. select from where group by
  59. select * from emp where max(salary) > 1000;
  60. 执行顺序
  61. from
  62. where
  63. group by
  64. select
  65. select max(salary) from emp;
  66. # 查询每个人的年薪
  67. select name,salary*12 from emp;
  68. 1. 查询岗位名以及岗位包含的所有员工名字group_concat()
  69. 2. 查询岗位名以及各岗位内包含的员工个数count()
  70. 3. 查询公司内男员工和女员工的个数 count()
  71. 4. 查询岗位名以及各岗位的平均薪资avg()
  72. 5. 查询岗位名以及各岗位的最高薪资max()
  73. 6. 查询岗位名以及各岗位的最低薪资min()
  74. 7. 查询男员工与男员工的平均薪资,女员工与女员工的平均薪资
  75. select sex,avg(salary) from emp group by sex;
  76. 8、统计各部门年龄在30岁以上的员工平均工资
  77. select * from emp where age>30;
  78. select post,avg(salary) from emp where age>30 group by post;
  79. having:
  80. 用法跟where一毛一样,having用在group by之后
  81. 也就意味着where不能用聚合函数,但是having可以
  82. from
  83. where
  84. group by
  85. having
  86. select
  87. 1、统计各部门年龄在30岁以上的员工平均工资,并且保留平均工资大于10000的部门
  88. select post,avg(salary) from emp where age > 30 group by post having avg(salary) > 10000;
  89. distinct:去重
  90. select post from emp;
  91. select distinct post from emp;
  92. from
  93. where
  94. group by
  95. having
  96. distinct
  97. select
  98. 6.order by:排序
  99. select * from emp order by salary asc; # 默认是升序
  100. select * from emp order by salary desc;
  101. select * from emp order by age,salary;
  102. select * from emp order by age desc,salary asc;
  103. # 统计各部门年龄在10岁以上的员工平均工资,并且保留平均工资大于1000的部门,然后对平均工资进行排序
  104. select post,avg(salary) from emp where age > 10 group by post having avg(salary) > 1000 order by avg(salary);
  105. limit:限制查询条数
  106. select * from emp limit 5;
  107. select * from emp limit 5,5;
  108. select * from emp limit 5,10;
  109. 如果写了俩参数,第一个参数表示起始位置,第二个参数表示的从第一个参数的位置开始往后获取的数据个数
  110. # 查询工资最高的人的信息
  111. select * from emp order by salary desc limit 1;
  112. % _
  113. 正则(regexp)
  114. 贪婪匹配与非贪婪匹配:.* .*?
  115. select * from emp where name regexp '^j.*(n|y)$';
  116. # 书写顺序
  117. select distinct * from '表名' where '限制条件' group by '分组依据' having '过滤条件' order by limit
  118. # 执行顺序
  119. from
  120. where
  121. group by
  122. having
  123. order by
  124. limit
  125. distinct
  126. select
  127. 多表操作
  128. create table dep(
  129. id int,
  130. name varchar(20)
  131. );
  132. create table emp(
  133. id int primary key auto_increment,
  134. name varchar(20),
  135. sex enum('male','female') not null default 'male',
  136. age int,
  137. dep_id int
  138. );
  139. 笛卡尔积
  140. select * from emp,dep where emp.dep_id = dep.id;
  141. # 查询部门为技术部的员工及部门信息
  142. # 1、内连接:只取两张表有对应关系的记录
  143. inner join
  144. select * from emp inner join dep on emp.dep_id = dep.id;
  145. # 2、左连接: 在内连接的基础上保留左表没有对应关系的记录
  146. left join
  147. # 3、右连接: 在内连接的基础上保留右表没有对应关系的记录
  148. right join
  149. # 4、全连接:在内连接的基础上保留左、右面表没有对应关系的的记录
  150. union
  151. 子查询
  152. # 1.查询部门是技术或者人力资源的员工信息
  153. select * from emp where dep_id in (select id from dep where name in ('技术','人力资源'));
  154. select * from emp where dep_id in (200201);
  155. # 2.每个部门最新入职的员工
  156. 思路:先查每个部门最新入职的员工,再按部门对应上联表查询
  157. select t1.id,t1.name,t1.hire_date,t1.post,t2.* from emp as t1
  158. inner join
  159. (select post,max(hire_date) as max_date from emp group by post) as t2
  160. on t1.post = t2.post
  161. where t1.hire_date = t2.max_date
  162. """
  163. 虚拟表!!!
  164. 记住一个规律,表的查询结果可以作为其他表的查询条件,
  165. 也可以通过其别名的方式把它作为一张虚拟表去跟其他表做关联查询!!!
  166. """

masql数据库的表查询的更多相关文章

  1. Entity Framework - Func引起的数据库全表查询

    原文:http://www.cnblogs.com/dudu/archive/2012/04/01/enitity_framework_func.html 使用 Entity Framework 最要 ...

  2. Vc数据库编程基础MySql数据库的表查询功能

    Vc数据库编程基础MySql数据库的表查询功能 一丶简介 不管是任何数据库.都会有查询功能.而且是很重要的功能.上一讲知识简单的讲解了表的查询所有. 那么这次我们需要掌握的则是. 1.使用select ...

  3. Mariadb/MySQL数据库单表查询基本操作及DML语句

    Mariadb/MySQL数据库单表查询基本操作及DML语句 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一数据库及表相关概述 1>.数据库操作 创建数据库: CREATE ...

  4. 关于oracle数据库 跨表查询建立 视图的方法

    工作中很多时候都会遇到需要将两个不同的表空间甚至数据库的表进行联合查询或者建立视图的情况. 不同的表空间查询我们可以通过在将要查询的表前面加上 表空间的对应的用户名来实现,如有两个表空间分别对应两个用 ...

  5. Mysql数据库多表查询

    一.介绍 首先说一下,我们写项目一般都会建一个数据库,那数据库里面是不是存了好多张表啊,不可能把所有的数据都放到一张表里面,肯定要分表来存数据,这样节省空间,数据的组织结构更清晰,解耦和程度更高,但是 ...

  6. oracle数据库单表查询

    今天给大家分享的是关于数据库的单表查询,像单表查询/多表查询/分组查询/子查询,这些方法的使用在实际项目过程中会经常用到,作为一名合格的测试人员如果不会数据库那肯定是不行的,行走江湖可能随时会面临被侮 ...

  7. Android程序猿必掌握的sqlite数据库连表查询

    SQL查询的基本原理:两种情况介绍. 第一.   单表查询:依据WHERE条件过滤表中的记录,形成中间表(这个中间表对用户是不可见的):然后依据SELECT的选择列选择对应的列进行返回终于结果. 第二 ...

  8. Mysql数据库单表查询

    1.单表查询语法 #查询数据的本质:mysql会到你本地的硬盘上找到对应的文件,然后打开文件,按照你的查询条件来找出你需要的数据.下面是完整的一个单表查询的语法 select * from,这个sel ...

  9. 11-Mysql数据库----单表查询

    本节重点: 单表查询 语法: 一.单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field ...

随机推荐

  1. 陪诊App,陪孝子找回人性

    2015年开始,越来越多的陪诊App开始上线,纷纷迎来了自己的第一批用户,同时,也迎来了大量资本的青睐,有些名气的问诊app甚至能单轮获得超过1000万元的融资,事实上,投资者是否青睐,简直就是中国新 ...

  2. Hive Functions

    函数的分类 内置函数 操作符 复杂对象 UDF函数 数学函数 类型转换函数 日期函数 条件函数 UDTF函数 常用UDTF函数 explode posexplode inline stack json ...

  3. MySQL安装和常用命令

    一.安装MySQL groupadd mysqluseradd -r -g mysql mysqlgroups mysqlfind / -name mysql | xargs rm -rfwget h ...

  4. Windows系统在Python2.7环境下安装numpy, matplotlib, scipy - Lichanghao Blog

    numpy, matplotlib, scipy三个包是科学计算和绘图的利器.安装它们既可以在网上下载exe安装包,也可以用python内置的包管理工具来下载安装,后者较为方便. 这几天做美赛要用到, ...

  5. Liferay7 Intellij IDEA 开发环境搭建

    一.安装Liferay插件 安装过程不在赘述,推荐两种安装方式: 通过Intellij插件市场安装 通过下载插件zip包安装 安装完成后,在项目板块中点鼠标右键,会出现Liferay菜单. 二.安装L ...

  6. C++学习之旅

    到现在为止学习C++也已经有一个半月了.一个半个月里我怀着好奇与敬畏一步步的走来,一步步的走向C++的内心深处,也发现了C++"内心的复杂".虽有坎坷,但从未放弃. 我承认,我不是 ...

  7. 1,Java知识储备

    1,关于 . java文件 规定:第一行为 package name; 表示该.java文件属于哪一个包. 一个.java文件中可以有多个类,但是只能有一个public类,并且这个public类必须与 ...

  8. SpringBoot一些基础配置

    定制banner Spring Boot项目在启动的时候会有一个默认的启动图案: . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( ...

  9. vue_相同组件,不同url跳转不重新渲染的解决方法

    最近写的这个项目,有很多下拉菜单,每个菜单会有相应的两种类型.现在产品的需求是,跳转到不同的类型 需要页面重新渲染数据 那么问题来了. 我试了好几种方法,用watch监听路由去判断,但是发现输在inp ...

  10. HTTPS 笔记

    随着互联网的迅速发展,网络安全问题日益凸显,现在 Chrome 浏览器已经开始阻止非 https 网站的访问了.对于 https 的流程一直不是十分清晰,借着还没有完全复工有时间,大概画了个图总结一下 ...