Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Useful for preparing for technical interviews and improving your SQL skills.
- [1393. Capital Gain/Loss](./leetcode/medium/1393.%20Capital%20Gain&Loss.sql)
- [1907. Count Salary Categories](./leetcode/medium/1907.%20Count%20Salary%20Categories.sql)
- [1934. Confirmation Rate](./leetcode/medium/1934.%20Confirmation%20Rate.sql)
- [3220. Odd and Even Transactions](./leetcode/medium/3220.%20Odd%20and%20Even%20Transactions.sql)
- [3475. DNA Pattern Recognition](./leetcode/medium/3475.%20DNA%20Pattern%20Recognition.sql)
- [3497. Analyze Subscription Conversion](./leetcode/medium/3497.%20Analyze%20Subscription%20Conversion.sql)
3. [Hard](./leetcode/hard/)
Expand Down
35 changes: 35 additions & 0 deletions leetcode/medium/3220. Odd and Even Transactions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Question 3220. Odd and Even Transactions
Link: https://leetcode.com/problems/odd-and-even-transactions/description/?envType=problem-list-v2&envId=database

Table: transactions

+------------------+------+
| Column Name | Type |
+------------------+------+
| transaction_id | int |
| amount | int |
| transaction_date | date |
+------------------+------+
The transactions_id column uniquely identifies each row in this table.
Each row of this table contains the transaction id, amount and transaction date.
Write a solution to find 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.
*/

SELECT
transaction_date,
SUM(CASE
WHEN amount % 2 = 1
THEN amount
ELSE 0
END) AS odd_sum,
SUM(CASE
WHEN amount % 2 = 0
THEN amount
ELSE 0
END) AS even_sum
FROM transactions
GROUP BY transaction_date
ORDER BY transaction_date ASC