1. Aggregate select
sum(revenue) aggregates each group and AS names the result column for later reference.
SELECT country, sum(revenue) AS totalTyporithm · easy
Step 1 of 8 · intro card
Spark SQL
Register a DataFrame as a temp view with createOrReplaceTempView, then query it with full SQL through spark.sql(...) — here a grouped revenue total per country.
Call df.createOrReplaceTempView("orders") to expose a DataFrame to the SQL engine under a name.
Once registered, spark.sql(...) runs any ANSI-style query against it — SELECT, GROUP BY, ORDER BY, and the full function library.
The result is just another DataFrame, so you can chain more transformations or write it out.
createOrReplaceTempView names a DataFrame for SQL.
spark.sql(...) runs full SQL over the view.
GROUP BY + sum() aggregates each group.
SELECT country, sum(revenue) AS total FROM orders GROUP BY country ORDER BY total DESCConnect each part of the code to the concept before you type.
sum(revenue) aggregates each group and AS names the result column for later reference.
SELECT country, sum(revenue) AS totalorders is the temp view registered from a DataFrame, queried here as if it were a table.
FROM ordersGROUP BY collapses rows sharing the same country into one aggregated row.
GROUP BY countryORDER BY total DESC sorts the grouped output from the highest revenue down.
ORDER BY total DESCRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.