Top META Trader by Transaction Volume

Coding · Medium · Free problem
Write a SQL query to find the trader(s) who had the most combined buy and sell transactions in META stock over the past 30 days. Include ties and return results ordered by total transaction count descending. You have access to the following table: **transactions_table** | Column | Type | | --- | --- | | transaction_date | datetime | | stock_symbol | text | | buyer_id | bigint | | seller_id | bigint | | transaction_id | bigint | | purchase_price | float | Expected output format: | trader_id | transactions | | --- | --- | | 12345 | 85 | **Constraints:** - A trader appears as `buyer_id` when buying and `seller_id` when selling - Count each transaction once per role (a transaction has one buyer and one seller) - Return all traders tied for the maximum - Filter to stock_symbol = 'META' and transaction_date within the last 30 days **Example:** - Trader 101 bought 50 times and sold 35 times -> 85 total transactions - Trader 202 bought 85 times and sold 0 times -> 85 total transactions - Both appear in output (tied at 85)

Open the full interactive solver, hints, and worked solution →