表信息:
--union多表联合查询
select * from Student_Table
union
select * from Employee_Table
union
select * from Teacher_Table
--union 排序
select 学生姓名 as 姓名 from Student_Table where 学生性别=1
union
select 员工姓名 from Employee_Table where 员工性别=0
order by 姓名 desc
--查询两表公共成员
select * from Student_Table
intersect
select * from Employee_Table
--查询两表除公共信息以外的信息
select 学生姓名 from Student_Table
except
select 员工姓名 from Employee_Table
--分组
select 学生姓名,sum(学生编号) as 编号 from Student_Table
group by 学生姓名
--having
select 学生姓名,sum(学生编号) as 编号 from Student_Table
group by 学生姓名
having sum(学生编号)>2
--select 中使用子查询
select
(select avg(学生编号) from Student_Table ) as 编号
from Student_Table
--from中使用子查询
select *
from (select 学生姓名,sum(学生编号) as 编号1,avg(学生编号) as 编号2 from Student_Table group by
学生姓名) tab1
order by 编号1
--where中使用子查询
select *
from Student_Table
where 学生年龄>(select AVG(学生年龄) from Student_Table)
--in中使用子查询
select * from
Student_Table
where 学生年龄 in(select 学生年龄 from Student_Table where 学生年龄 between 20 and 30 )
--exists中使用子查询
select * from
Student_Table AS A
where EXISTS(SELECT 学生编号 from Student_Table where 学生编号=A.学生编号)
--any
select * from Student_Table
where 学生年龄>any(select 学生年龄 from Student_Table)
--all
select * from Student_Table
where 学生年龄>all(select 学生年龄 from Student_Table where 学生性别=0)
--子查询嵌套
select * from Student_Table
where 学生年龄>(SELECT AVG(学生年龄) from Student_Table where 出生日期>(select avg(year(出生日期)) from Student_Table ))