SQL语句问题【急。。。。。。。。。。。。。。。。。。。。。。】
小飛不想飛 2013-07-26 09:49:59 子查询的数据小于外查询的数据不一致怎么办?
例如:
学生表(student):
StudentID name age class Grade
1 张三 16 1 4
2 李四 15 5
3 王五 17
4 赵六 16 2
班级/年级表(class):
classID type className
1 class 1班
2 class 2班
3 class 3班
4 grade 5年级
5 grade 6年级
我想要的查询结果:
StudentID name age className grade
1 张三 16 1班 5年级
2 李四 15 6年级
3 王五 17
4 赵六 16 2班
我的查询语句:
select studentId,name,age,(select className from class where classId = a.class and type = 'class') className,(select className from class where classId = a.Grade and type = 'grade') grade from student a
Ps:因为学生表中班级和年级字段有的是空的,所以子查询的数据少了,报错:值过多。
如果想得到我要的查询结果该怎么查?