Meta SQL Interview Questions on Grouped Sales, Invited Customers, and Author Metrics

19 Views
No Comments

This set of SQL interview questions uses a bookstore database with the following tables: books, authors, transactions, and customers.

books

  • book_id INT (KEY)
  • title VARCHAR
  • author_id INT
  • publication_date DATE
  • category VARCHAR
  • price DOUBLE

authors

  • author_id INT (KEY)
  • first_name VARCHAR
  • last_name VARCHAR
  • birthday DATE
  • website_url VARCHAR

transactions

  • transaction_id INT (KEY)
  • book_id INT
  • customer_id INT
  • payment_amount DOUBLE
  • book_count INT
  • tax_rate DOUBLE
  • discount_rate DOUBLE
  • transaction_date DATE
  • payment_type VARCHAR

customers

  • customer_id INT (KEY)
  • first_name VARCHAR
  • last_name VARCHAR
  • registration_date DATE
  • interested_in_categories VARCHAR
  • is_rewards_member BOOLEAN
  • invited_by_customer_id INT

Questions

  • What was the total value of sales and the number of unique paying customers, grouped and sorted in descending order by payment type?
  • Existing customers can invite other people to sign up to the bookstore. Find the IDs of the top 5 customers, ordered by the average payment per book made by the people they invited.
  • Find the total number of authors. What percentage of them have a website URL that contains .com, and what percentage never made a sale?

This Meta SQL problem focuses on grouped aggregation, relationship traversal, and percentage-based analysis. The first query groups transactions by payment type and computes total sales and the number of distinct paying customers. The second query follows the invitation chain through customers.invited_by_customer_id, then ranks inviters by the average payment per book made by the customers they invited. The third query is an author-level analysis that counts all authors, measures the share whose website URL contains ".com", and finds the share of authors who never made a sale. Overall, the key techniques are GROUP BY, COUNT(DISTINCT …), joins, and conditional aggregation.

END
 0