{ "data": { "question": { "questionId": "3530", "questionFrontendId": "3220", "categoryTitle": "Database", "boundTopicId": 2847569, "title": "Odd and Even Transactions", "titleSlug": "odd-and-even-transactions", "content": "
Table: transactions
\n+------------------+------+\n| Column Name | Type | \n+------------------+------+\n| transaction_id | int |\n| amount | int |\n| transaction_date | date |\n+------------------+------+\nThe transactions_id column uniquely identifies each row in this table.\nEach row of this table contains the transaction id, amount and transaction date.\n\n\n
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.
The result format is in the following example.
\n\n\n
Example:
\n\nInput:
\n\ntransactions
table:
\n+----------------+--------+------------------+\n| transaction_id | amount | transaction_date |\n+----------------+--------+------------------+\n| 1 | 150 | 2024-07-01 |\n| 2 | 200 | 2024-07-01 |\n| 3 | 75 | 2024-07-01 |\n| 4 | 300 | 2024-07-02 |\n| 5 | 50 | 2024-07-02 |\n| 6 | 120 | 2024-07-03 |\n+----------------+--------+------------------+\n\n\n
Output:
\n\n\n+------------------+---------+----------+\n| transaction_date | odd_sum | even_sum |\n+------------------+---------+----------+\n| 2024-07-01 | 75 | 350 |\n| 2024-07-02 | 0 | 350 |\n| 2024-07-03 | 0 | 120 |\n+------------------+---------+----------+\n\n\n
Explanation:
\n\nNote: The output table is ordered by transaction_date
in ascending order.
表:transactions
\n+------------------+------+\n| Column Name | Type | \n+------------------+------+\n| transaction_id | int |\n| amount | int |\n| transaction_date | date |\n+------------------+------+\ntransactions_id 列唯一标识了表中的每一行。\n这张表的每一行包含交易 id,金额总和和交易日期。\n\n\n
编写一个解决方案来查找每天 奇数 交易金额和 偶数 交易金额的 总和。如果某天没有奇数或偶数交易,显示为 0
。
返回结果表以 transaction_date
升序 排序。
结果格式如下所示。
\n\n\n\n
示例:
\n\n输入:
\n\ntransactions
表:
\n+----------------+--------+------------------+\n| transaction_id | amount | transaction_date |\n+----------------+--------+------------------+\n| 1 | 150 | 2024-07-01 |\n| 2 | 200 | 2024-07-01 |\n| 3 | 75 | 2024-07-01 |\n| 4 | 300 | 2024-07-02 |\n| 5 | 50 | 2024-07-02 |\n| 6 | 120 | 2024-07-03 |\n+----------------+--------+------------------+\n\n\n
输出:
\n\n\n+------------------+---------+----------+\n| transaction_date | odd_sum | even_sum |\n+------------------+---------+----------+\n| 2024-07-01 | 75 | 350 |\n| 2024-07-02 | 0 | 350 |\n| 2024-07-03 | 0 | 120 |\n+------------------+---------+----------+\n\n\n
解释:
\n\n注意:输出表以 transaction_date
升序排序。
\\u7248\\u672c\\uff1a mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\" Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\" Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\" PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"transactions\":[\"transaction_id\",\"amount\",\"transaction_date\"]},\"rows\":{\"transactions\":[[1,150,\"2024-07-01\"],[2,200,\"2024-07-01\"],[3,75,\"2024-07-01\"],[4,300,\"2024-07-02\"],[5,50,\"2024-07-02\"],[6,120,\"2024-07-03\"]]}}",
"__typename": "QuestionNode"
}
}
}MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"