Skip to content

Commit 5924813

Browse files
committed
task: #3220
1 parent 65e9270 commit 5924813

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ Useful for preparing for technical interviews and improving your SQL skills.
175175
- [1393. Capital Gain/Loss](./leetcode/medium/1393.%20Capital%20Gain&Loss.sql)
176176
- [1907. Count Salary Categories](./leetcode/medium/1907.%20Count%20Salary%20Categories.sql)
177177
- [1934. Confirmation Rate](./leetcode/medium/1934.%20Confirmation%20Rate.sql)
178+
- [3220. Odd and Even Transactions](./leetcode/medium/3220.%20Odd%20and%20Even%20Transactions.sql)
178179
- [3475. DNA Pattern Recognition](./leetcode/medium/3475.%20DNA%20Pattern%20Recognition.sql)
179180
- [3497. Analyze Subscription Conversion](./leetcode/medium/3497.%20Analyze%20Subscription%20Conversion.sql)
180181
3. [Hard](./leetcode/hard/)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Question 3220. Odd and Even Transactions
3+
Link: https://leetcode.com/problems/odd-and-even-transactions/description/?envType=problem-list-v2&envId=database
4+
5+
Table: transactions
6+
7+
+------------------+------+
8+
| Column Name | Type |
9+
+------------------+------+
10+
| transaction_id | int |
11+
| amount | int |
12+
| transaction_date | date |
13+
+------------------+------+
14+
The transactions_id column uniquely identifies each row in this table.
15+
Each row of this table contains the transaction id, amount and transaction date.
16+
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.
17+
18+
Return the result table ordered by transaction_date in ascending order.
19+
*/
20+
21+
SELECT
22+
transaction_date,
23+
SUM(CASE
24+
WHEN amount % 2 = 1
25+
THEN amount
26+
ELSE 0
27+
END) AS odd_sum,
28+
SUM(CASE
29+
WHEN amount % 2 = 0
30+
THEN amount
31+
ELSE 0
32+
END) AS even_sum
33+
FROM transactions
34+
GROUP BY transaction_date
35+
ORDER BY transaction_date ASC

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy