Mysql中的DQL查询语句(二)
=2 and xx.成绩>80
--加了 表名.列名 (一般无需在列名之前加表名前缀,只有当两个表有相同的列名时才加前缀) select xs.姓名,xx.成绩 from xs,xx where xs.学号=xx.学号 --两表链接条件 and xx.课程号=2 and xx.成绩>80
-----------------------查询 刘德华的成绩 --方式一 省略前缀 select xx.成绩 from xx,xs where xx.学号=xs.学号 and 姓名='刘德华'
--方式二 嵌套查询 select 成绩 from xx where 学号= ( select 学号 from xs where 姓名='刘德华' )
--方式三 内联式查询 select xx.成绩 from xx join xs on xs.学号=xx.学号 --两表连接条件 where 姓名='刘德华' --其他限制条件
--查询林心如的古汉语成绩 select 姓名, 课程名 ,xx.成绩
from xs join xx on xs.学号=xx.学号 join kc on kc.课程号=xx.课程号 and 姓名='林心如' and 课程名='古汉语'
select 姓名 ,课程名 ,xx.成绩 from xs,xx,kc where xs.学号=xx.学号 and xx.课程号=kc.课程号 and 姓名='林心如' and 课程名='古汉语'
select 成绩 from xx where 课程号= ( select 课程号 from kc where 课程名='古汉语' ) and 学号= ( select 学号 from xs where 姓名='林心如' )