Given a function that returns 0 or 1 randomly, create a random number generator; then explain how you would delete duplicates in an SQL table.
For the SQL portion, treat rows with identical event attributes as duplicates and retain the row with the smallest trade_id. The query should remove duplicates and return the IDs of the deleted rows.
duplicate_trade_idduplicate_trade_id ascending| Column | Type | Description |
|---|---|---|
| trade_idPK | BIGINT | Unique identifier for the trade event |
| account_id | VARCHAR(32) | Trading account identifier |
| event_time | TIMESTAMP | Time at which the event occurred |
| symbol | VARCHAR(16) | Security ticker symbol |
| side | VARCHAR(16) | Trade action |
| quantity | NUMERIC(18,4) | Number of units in the event |
| price | NUMERIC(18,4) | Execution price per unit |