Skip to content

13. Order Lines with Product Details

Difficulty: Easy · Topics: Joins, Filtering & Selection

order_lines has order_id, product_id and qty. products has product_id, name and price.

Return order_id, name, qty and line_total (qty × price) for every order line whose product exists in products. Lines with an unknown product are left out.

Row order does not matter; column names must match. Your code is graded on 3 test cases, including hidden edge cases.

Sample data

order_lines

order_idproduct_idqty
10012
10021
10135
10291

products

product_idnameprice
1Notebook50
2Pen10
3Stapler250

Expected output

order_idnameqtyline_total
100Notebook2100
100Pen110
101Stapler51250

Hints

Hint 1An inner join keeps only lines whose product matches.
Hint 2Join on the column name, "product_id", so the result has a single key column.
Hint 3Compute line_total after the join, when price is available.

Learn the concepts

PySpark functions you'll practise

Related problems

Browse

Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings

Difficulty: Easy · Medium · Hard · PySpark interview roadmap · Learn · All problems