{ "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
\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.

\n\n

Return the result table ordered by transaction_date in ascending order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example:

\n\n
\n

Input:

\n\n

transactions table:

\n\n
\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\n\n\n

Note: The output table is ordered by transaction_date in ascending order.

\n
\n", "translatedTitle": "奇数和偶数交易", "translatedContent": "

表:transactions

\n\n
\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

\n\n

返回结果表以 transaction_date 升序 排序。

\n\n

结果格式如下所示。

\n\n

 

\n\n

示例:

\n\n
\n

输入:

\n\n

transactions 表:

\n\n
\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\n\n

注意:输出表以 transaction_date 升序排序。

\n
\n", "isPaidOnly": false, "difficulty": "Medium", "likes": 0, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false, \"cangjie\": false}", "topicTags": [ { "name": "Database", "slug": "database", "translatedName": "数据库", "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode" }, { "lang": "Pandas", "langSlug": "pythondata", "code": "import pandas as pd\n\ndef sum_daily_odd_even(transactions: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" }, { "lang": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL query statement below", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"408\", \"totalSubmission\": \"548\", \"totalAcceptedRaw\": 408, \"totalSubmissionRaw\": 548, \"acRate\": \"74.5%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"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\"]]}}", "metaData": "{\"mysql\":[\"Create table if not exists transactions ( transaction_id int, amount int, transaction_date date)\"],\"mssql\":[\"Create table transactions ( transaction_id int, amount int, transaction_date date)\"],\"oraclesql\":[\"Create table transactions ( transaction_id int, amount int, transaction_date date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"sum_daily_odd_even\",\"postgresql\":[\"CREATE TABLE IF NOT EXISTS transactions (\\n transaction_id int,\\n amount int,\\n transaction_date date\\n);\\n\"],\"pythondata\":[\"transactions = pd.DataFrame(\\n columns=[\\\"transaction_id\\\", \\\"amount\\\", \\\"transaction_date\\\"],\\n dtype={\\n \\\"transaction_id\\\": \\\"int\\\",\\n \\\"amount\\\": \\\"int\\\",\\n \\\"transaction_date\\\": \\\"datetime64[ns]\\\",\\n },\\n)\\n\"],\"database_schema\":{\"transactions\":{\"transaction_id\":\"INT\",\"amount\":\"INT\",\"transaction_date\":\"DATE\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table if not exists transactions ( transaction_id int, amount int, transaction_date date)", "Truncate table transactions", "insert into transactions (transaction_id, amount, transaction_date) values ('1', '150', '2024-07-01')", "insert into transactions (transaction_id, amount, transaction_date) values ('2', '200', '2024-07-01')", "insert into transactions (transaction_id, amount, transaction_date) values ('3', '75', '2024-07-01')", "insert into transactions (transaction_id, amount, transaction_date) values ('4', '300', '2024-07-02')", "insert into transactions (transaction_id, amount, transaction_date) values ('5', '50', '2024-07-02')", "insert into transactions (transaction_id, amount, transaction_date) values ('6', '120', '2024-07-03')" ], "enableRunCode": true, "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

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" } } }