This question evaluates SQL querying skills including aggregation and grouping, date/time windowing for previous-calendar-month calculations, joins and handling absence of rows to identify top spenders and users with no transactions.
Assume the following schema:
users(user_id, created_at, ...)
transactions(txn_id, user_id, amount, txn_ts)
amount
is a positive number for a successful purchase.
Write a SQL query to find the user(s) with the largest total spend in the previous calendar month.
Write a SQL query to find users who have never made a purchase (no rows in transactions).
If you need additional assumptions (timezone, refunds, ties), state them explicitly.