You are given a transactions table containing transaction details including transaction ID, amount, and date.
Goal: Calculate the sum of amounts for odd and even transactions for each day. If there are no odd or even transactions for a specific date, display as 0.
Return the result table ordered by transaction_date in ascending order.
Table Structure:
transaction_id(int): Unique identifier for each transactionamount(int): Transaction amounttransaction_date(date): Date when transaction occurred
Table Schema
| Column Name | Type | Description |
|---|---|---|
transaction_id
PK
|
int | Unique identifier for each transaction |
amount
|
int | Transaction amount |
transaction_date
|
date | Date when transaction occurred |
Input & Output
| transaction_id | amount | transaction_date |
|---|---|---|
| 2 | 150 | 2022-09-01 |
| 1 | 300 | 2022-09-01 |
| 13 | 600 | 2022-09-02 |
| transaction_date | odd_sum | even_sum |
|---|---|---|
| 2022-09-01 | 300 | 150 |
| 2022-09-02 | 600 | 0 |
For 2022-09-01: transaction_id 1 (odd) has amount 300, transaction_id 2 (even) has amount 150. For 2022-09-02: only transaction_id 13 (odd) exists with amount 600, so even_sum is 0.
| transaction_id | amount | transaction_date |
|---|---|---|
| 2 | 200 | 2022-09-01 |
| 4 | 400 | 2022-09-01 |
| transaction_date | odd_sum | even_sum |
|---|---|---|
| 2022-09-01 | 0 | 600 |
Only even transaction_ids exist (2 and 4) with amounts 200 and 400 respectively, so odd_sum is 0 and even_sum is 600.
| transaction_id | amount | transaction_date |
|---|---|---|
| 1 | 100 | 2022-09-01 |
| 2 | 200 | 2022-09-02 |
| 3 | 300 | 2022-09-02 |
| transaction_date | odd_sum | even_sum |
|---|---|---|
| 2022-09-01 | 100 | 0 |
| 2022-09-02 | 300 | 200 |
2022-09-01 has only odd transaction (id=1, amount=100). 2022-09-02 has both odd (id=3, amount=300) and even (id=2, amount=200) transactions.
Constraints
-
1 ≤ transaction_id ≤ 10^5 -
1 ≤ amount ≤ 10^5 -
transaction_dateis a valid date