标签:dai 左外连接 分享图片 dia oss 基本 .com uid sel
数据库连接关系图学生表与班级表取左外连接
select s.stuid,s.name,c.class from students as s left join classes as c on s.classid=c.classid;
+-------+---------------+----------------+
| stuid | name | class |
+-------+---------------+----------------+
| 1 | Shi Zhongyu | Emei Pai |
| 2 | Shi Potian | Shaolin Pai |
| 3 | Xie Yanke | Emei Pai |
| 4 | Ding Dian | Wudang Pai |
| 5 | Yu Yutong | QingCheng Pai |
| 6 | Shi Qing | Riyue Shenjiao |
| 7 | Xi Ren | QingCheng Pai |
| 8 | Lin Daiyu | Ming Jiao |
| 9 | Ren Yingying | Lianshan Pai |
| 10 | Yue Lingshan | QingCheng Pai |
| 11 | Yuan Chengzhi | Lianshan Pai |
| 12 | Wen Qingqing | Shaolin Pai |
| 13 | Tian Boguang | Emei Pai |
| 14 | Lu Wushuang | QingCheng Pai |
| 15 | Duan Yu | Wudang Pai |
| 16 | Xu Zhu | Shaolin Pai |
| 17 | Lin Chong | Wudang Pai |
| 18 | Hua Rong | Ming Jiao |
| 19 | Xue Baochai | Lianshan Pai |
| 20 | Diao Chan | Ming Jiao |
| 21 | Huang Yueying | Lianshan Pai |
| 22 | Xiao Qiao | Shaolin Pai |
| 23 | Ma Chao | Wudang Pai |
# | 24 | Xu Xian | NULL |
# | 25 | Sun Dasheng | NULL |
+-------+---------------+----------------+
学生表与班级表取左外连接,并且减去学生表与课程表交集部分
select s.stuid,s.name,c.class from students as s left join classes as c on s.classid=c.classid where c.classid is NULL;
+-------+-------------+-------+
| stuid | name | class |
+-------+-------------+-------+
| 24 | Xu Xian | NULL |
| 25 | Sun Dasheng | NULL |
+-------+-------------+-------+
计算女生成绩的平均值
select avg(age) from students group by gender having gender=‘F‘;
标签:dai 左外连接 分享图片 dia oss 基本 .com uid sel
原文地址:http://blog.51cto.com/11034229/2069616