异常
20/04/19 15:47:10 INFO SparkSqlParser: Parsing command: select stu.* from Student stu join Score sco on stu.Sno=sco.Sno and sco.Cno='3-105' and sco.Degree >(select max(Degree) from Score where Sno='109' order by Degree desc)
Exception in thread "main" org.apache.spark.sql.AnalysisException: Table or view not found: `Score`; line 1 pos 130;
'Project [ArrayBuffer(stu).*]
+- 'Join Inner, (((Sno#0 = Sno#18) && (Cno#19 = 3-105)) && (Degree#20 > scalar-subquery#42 []))
: +- 'Sort ['Degree DESC NULLS LAST], true
: +- 'Project [unresolvedalias('max('Degree), None)]
: +- 'Filter ('Sno = 109)
: +- 'UnresolvedRelation `Score`
:- SubqueryAlias stu
: +- SubqueryAlias student
: +- Relation[Sno#0,Sname#1,Ssex#2,Sbirthday#3,Class#4] JDBCRelation(Student) [numPartitions=1]
+- SubqueryAlias sco
+- SubqueryAlias score
+- Relation[Sno#18,Cno#19,Degree#20] JDBCRelation(Score) [numPartitions=1]
原因 是语句有问题 在写子查询的时候,子查询返回的结果只能是一个值,返回了两个值
## 错误的
spark.sql("select stu.* from Student stu join Score sco on stu.Sno=sco.Sno and sco.Cno='3-105' and sco.Degree >(select max(Degree) from Score where Sno='109' order by Degree desc)").show()
## 正确的
// spark.sql("select * from Score sco where sco.Cno='3-105' and sco.Degree > (select Degree from Score where Sno='109' and Cno='3-105')").show()