左连接查询:
进行左连接查询时,可以查出表名1中所指的表中所有记录。而表名2所指表中,只能查询出匹配的记录。
实例:
右连接查询:
与左连接相反,可以查询出表名2中的的所有记录,而表名1中所指的表中,只查询出匹配的记录。
PS:使用集合函数查询
集合函数包括count(),sum(),avg(),max()和min()。
1)count()函数
统计记录条数
实例:
| select count(*) from employee; |
与group by一起使用
| select d_id,count(*) from employee group by d_id; |
上述语句会先分组后统计。
2) sum()函数
sum()函数是求和函数
实例:
| select num,sum(score) from grade where num= 1001; select num,sum(score) from grade group by num; |
sum()只能计算数值类型字段。
3)avg()函数
avg()函数是求平均值函数。
实例:
| select avg(age) from employee; select course,avg(score) from group by course; |
4)max(),min()函数
求最大值和最小值。
实例:
select max(age) from employee;
select num,course,max(score) from grade group by course;
对于字符串的最大值问题,max()函数是使用字符对应的ascii码进行计算的。










