Murat
Murat

Reputation: 23

Create Tempview from sql query

df_sales = spark.sql(
"SELECT \
s.TRANS_DT, \
s.STORE_KEY, \
s.PROD_KEY, \
s.SALES_QTY
FROM sales s \
JOIN inventory i ON s.cal_dt=i.cal_dt and s.store_key=i.store_key and s.prod_key=i.prod_key;"
)

I created sql query from 2 tempview (inventory and sales). How to convert df_sales sql query to tempview again and I can create a new SQL query.

Upvotes: 1

Views: 127

Answers (1)

Guoran Yun
Guoran Yun

Reputation: 339

Read this and you can write your own code as follows:

spark.sql(
"""
SELECT
    s.TRANS_DT,
    s.STORE_KEY,
    s.PROD_KEY,
    s.SALES_QTY
FROM sales s
JOIN inventory i ON s.cal_dt=i.cal_dt and s.store_key=i.store_key and s.prod_key=i.prod_key;
"""
).createOrReplaceTempView("tmpViewName")

Upvotes: 2

Related Questions