s '班级' ,
address as '地址' , phone as '联系方式', Grade.gradeName as '年级'
from Grade left join Student on Student.gradeId = Grade.id --右连接查询 select
Student.id as '学号' , name as '姓名' , age as '年龄' , gradeId as '班级' ,
address as '地址' , phone as '联系方式', Grade.gradeName as '年级'
from Student RIGHT join Grade on Student.gradeId = Grade.id
--FULL连接查询 select
Student.id as '学号' , name as '姓名' , age as '年龄' , gradeId as '班级' ,
address as '地址' , phone as '联系方式', Grade.gradeName as '
年级' from Student FULL JOIN Grade on Student.gradeId = Grade.id --内连接查询 select Student.id as '学号' , name as '姓名' , age as '年龄' , gradeId as '班级' , address as '地址' , phone as '联系方式', Grade.gradeName as '年级' from Student inner join Grade on Student.gradeId = Grade.id
UNION 查询
UNION 操作符用于合并两个或多个 SELECT 语句的结果集。
请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。
--UNION 查询,联合查询 select 1,2,3,4,5 from Student union select 1,2,3,4,5 from Grade select name , age ,sex from Student union select null , null , null from Grade order by 1
SQL 聚合函数
聚合函数对一组值执行计算,并返回单个值。除了 COUNT 以外,聚合函数都会忽略空值。聚合函数经常与 SELECT 语句的 GROUP BY 子句一起使用。
聚合函数只能在以下位置作为表达式使用:
1、SELECT 语句的选择列表(子查询或外部查询)。 2、COMPUTE 或 COMPUTE BY 子句。 3、HAVING 子句。 年龄
datediff(yy,出生日期,getdate())
AVG 平均数 MIN 最小值 SUM 总数 COUNT 统计个数 MAX 最大值
分组:
select 类别, sum(数量) as 数量之和 from A group by 类别
相关推荐: