Menu

Final Project SQL

Final Project SQL - image 1 - student project

Descriptions:

This query uses CTEs (WITH clauses) to build two result sets and then combines them with UNION:

  • subs CTE: aggregates the orders table to compute, for each customer_id, how many subscriptions they have (COUNT(subscription_id)), labeled as nbr_of_subscriptions.
  • tony_subs CTE: creates a manual/constant row that represents a customer named Tony with 5 subscriptions (useful for testing or appending a special-case row).
  • Final SELECT:
    • Joins subs with customers to output each customer’s name and their computed subscription count.
    • Uses UNION to append the Tony row from tony_subs to the end of the results.

Result: a list of customers with their number of subscriptions, plus an extra row: Tony | 5.