软件测试培训第4天

       继昨天的Mysql数据库的部分查询系统之后,今天则把软件测试中用到的查询命令全部学完,分别是高级查询中的连接查询,联合查询,以及相关子查询。高级查询要比昨天所学的查询复杂不少,命令也比较多,而Mysql的习题难度也非常的大,后面的题目都需要很长一段命令才可以实现,前提必须有十分清晰的思路逐步分解,而紧接着明天也将迎来Mysql的考试,在现在自己还没完全掌握的情况下,明天的考试将会是一场苦战吧……

整理得查询命令:Mysql名词:
创建表:1.字段名2.数据类型3.约束。1和2必须有
表名,字段=条件=条件名,数值
1.简单查询:from后加表名
句型1:select * from 表名;
句型2:select 字段,字段,字段……from 表名;
句型3条件名的修改:select 字段 as 新字段,字段 as 新字段 from 表名;
2.条件查询:where后加字段
句型1:select * from 表名 where 字段="数值";
句型2where后用and连接起两个不同 字段="数值":
       select * from 表名 where 字段="数值" and 字段="数值";
句型3也可用or连接,and和or可以同时使用:
       select * from 表名 where 字段="数值" and 字段="数值" or 字段="数值";
3.模糊查询:where 字段后面+like/not like
句型1(%代表任意多个字符):
       select * from 表名 where 字段 like "%数值";
句型2:(_代表一个字符):
       select * from 表名 where 字段 like "_数值";
4.排序查询:在from 表名之后接 order by 再接字段接desc(降序)/asc(升序默认的)
句型1:select from 表名 order by 字段 desc/asc;
句型2按某字段升+某字段降:
       select from 表名 order by 字段1 asc,字段2desc;
5.范围查询:在字段后接>,<,=,!=,between
句型1用符号表示:
       select from 表名 where 字段>数字 and 字段<数字;
句型2用between表示:
       select from 表名 where 字段 between 数字小 and 数字大;
6.离散查询:where 字段接in("数值")
句型1:select * from 表名 where 字段 in ("数值");
7.聚合函数:select 接函数(字段)
句型1:select 函数(字段)from 表名;
句型2:select 函数(*)from 表名;
8.分页查询:from 表名接limit,where命令后方不可直接加limit
句型1:select * from 表名 limit 数字,数字;
9.去重查询:select后接distinct
句型1:select distinct 字段 from 表名;
10.分组查询:函数后(字段)
句型1:select 接字段,函数(字段)from 表名 group by 字段 having 函数(字段)>,<,=,!=;
11.连接查询:表名1.字段1=表名2.字段2可以这样简化
句型1:select * from 表名 where 表名1.字段1=表名2.字段2 and 表名2.字段=103;
句型2:from 表名接join 表名 on 接表名.字段
       Select * from Teacher
Join course
On Teacher.tno=Course.tno
Join Score
On Course.cno=Score.cno
12.联合查询:两句select语句用union
句型1:select Code,Name from Info
    union
    select Code,Name from Nation;
13.子查询:select(select);
句型1:
      select Code from Nation where Name='汉族'
      select * from Info where Nation = ''
整合:select * from Info where Nation = (select Code from Nation where Name='汉族')

原文地址:https://www.cnblogs.com/k874146812-/p/7782189.html