From 024e993c9a256f96a0fa4459830033fd1dd7dc1a Mon Sep 17 00:00:00 2001 From: ivanbyone Date: Thu, 17 Jul 2025 22:28:24 +0300 Subject: [PATCH] task: #3220 --- README.md | 1 + .../3220. Odd and Even Transactions.sql | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 leetcode/medium/3220. Odd and Even Transactions.sql diff --git a/README.md b/README.md index a7630ab..4179849 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/leetcode/medium/3220. Odd and Even Transactions.sql b/leetcode/medium/3220. Odd and Even Transactions.sql new file mode 100644 index 0000000..677f9f2 --- /dev/null +++ b/leetcode/medium/3220. Odd and Even Transactions.sql @@ -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