How would you write SQL queries involving ordering and joins to extract the right records under time constraints?
Use the provided orders, order_events, instruments, and fills tables. Return the latest January 2025 order per instrument, keeping only orders whose latest non-null event is FILLED or PARTIALLY_FILLED. Rows with NULL submitted_at or NULL event_time are ignored.
Output
- One row per qualifying instrument and order, with the columns listed below.
- Include the instrument symbol, order ID, latest event type, submission time, filled quantity, average fill price, and latest fill time.
- Sort by submission time descending, instrument symbol ascending, and order ID ascending.