当前位置:网站首页>Spark Sql之join on and和where
Spark Sql之join on and和where
2022-08-01 23:23:00 【南风知我意丿】
需求

如何实现上图需求。先给出结论:join whre
join where
val df1: DataFrame = sc.makeRDD(Seq((1, "xm"), (2, "xl"), (3, "xw"))).toDF("id", "name")
df1.show()
df1.createOrReplaceTempView("t1")
val df2: DataFrame = sc.makeRDD(Seq(1,2)).toDF("id")
df2.createOrReplaceTempView("t2")
df2.show()
println("------------------------where------------------------------------")
val sql1:String =
s""" |select t1.id,t1.name from t1 |left join t2 |on t1.id = t2.id |where t2.id is NULL |""".stripMargin
session.sql(sql1).show()
+---+----+
| id|name|
+---+----+
| 1| xm|
| 2| xl|
| 3| xw|
+---+----+
+---+
| id|
+---+
| 1|
| 2|
+---+
------------------------where------------------------------------
+---+----+
| id|name|
+---+----+
| 3| xw|
+---+----+
join and
println("------------------------and------------------------------------")
val sql2:String =
s""" |select t1.id,t1.name from t1 |left join t2 |on t1.id = t2.id |and t2.id is NULL |""".stripMargin
session.sql(sql2).show()
------------------------and------------------------------------
+---+----+
| id|name|
+---+----+
| 1| xm|
| 2| xl|
| 3| xw|
+---+----+
原因分析
sql执行顺序:
FROM
ON
JOIN
WHERE
GROUP BY
WITH CUBE or WITH ROLLUP
HAVING
SELECT
DISTINCT ORDER BY TOP
详细解释连接参考我之前写的文章
边栏推荐
猜你喜欢

深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练
![[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环](/img/63/16de443caf28644d79dc6e6889e5dd.png)
[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环

Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training

UML diagram of soft skills

伸展树的特性及实现

还在纠结报表工具的选型么?来看看这个

From 0 to 1: Design and R&D Notes of Graphic Voting Mini Program

drf生成序列化类代码
![[Camp Experience Post] 2022 Cybersecurity Summer Camp](/img/1e/716bafc679dc67d3d54bcc21a3b670.png)
[Camp Experience Post] 2022 Cybersecurity Summer Camp

C语言——分支语句和循环语句
随机推荐
E - Integer Sequence Fair
excel remove all carriage return from a cell
Thesis understanding [RL - Exp Replay] - Experience Replay with Likelihood-free Importance Weights
数据机构---第五章树与二叉树---二叉树的概念---应用题
【参营经历贴】2022网安夏令营
LocalDateTime转为Date类型
论文理解【RL - Exp Replay】—— Experience Replay with Likelihood-free Importance Weights
解决端口占用
Calculate the distance between two points
C语言——分支语句和循环语句
从0到1:图文投票小程序设计与研发笔记
excel change cell size
计算两点之间的中点
2022/7/31
SQL Server (design database--stored procedure--trigger)
欧拉路径与欧拉回路
基于JAX的激活函数、softmax函数和交叉熵函数
Making a Simple 3D Renderer
【好书推荐】第一本无人驾驶技术书
What can be done to make this SQL into a dangerous SQL?