{ "data": { "question": { "questionId": "1278", "questionFrontendId": "1164", "categoryTitle": "Database", "boundTopicId": 33161, "title": "Product Price at a Given Date", "titleSlug": "product-price-at-a-given-date", "content": "

Table: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| new_price     | int     |\n| change_date   | date    |\n+---------------+---------+\n(product_id, change_date) is the primary key (combination of columns with unique values) of this table.\nEach row of this table indicates that the price of some product was changed to a new price at some date.
\n\n

Initially, all products have price 10.

\n\n

Write a solution to find the prices of all products on the date 2019-08-16.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nProducts table:\n+------------+-----------+-------------+\n| product_id | new_price | change_date |\n+------------+-----------+-------------+\n| 1          | 20        | 2019-08-14  |\n| 2          | 50        | 2019-08-14  |\n| 1          | 30        | 2019-08-15  |\n| 1          | 35        | 2019-08-16  |\n| 2          | 65        | 2019-08-17  |\n| 3          | 20        | 2019-08-18  |\n+------------+-----------+-------------+\nOutput: \n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2          | 50    |\n| 1          | 35    |\n| 3          | 10    |\n+------------+-------+\n
\n", "translatedTitle": "指定日期的产品价格", "translatedContent": "

产品数据表: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| new_price     | int     |\n| change_date   | date    |\n+---------------+---------+\n(product_id, change_date) 是此表的主键(具有唯一值的列组合)。\n这张表的每一行分别记录了 某产品 在某个日期 更改后 的新价格。
\n\n

一开始,所有产品价格都为 10。

\n\n

编写一个解决方案,找出在 2019-08-16 所有产品的价格。

\n\n

任意顺序 返回结果表。

\n\n

结果格式如下例所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nProducts 表:\n+------------+-----------+-------------+\n| product_id | new_price | change_date |\n+------------+-----------+-------------+\n| 1          | 20        | 2019-08-14  |\n| 2          | 50        | 2019-08-14  |\n| 1          | 30        | 2019-08-15  |\n| 1          | 35        | 2019-08-16  |\n| 2          | 65        | 2019-08-17  |\n| 3          | 20        | 2019-08-18  |\n+------------+-----------+-------------+\n输出:\n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2          | 50    |\n| 1          | 35    |\n| 3          | 10    |\n+------------+-------+
\n", "isPaidOnly": false, "difficulty": "Medium", "likes": 240, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python3\": false, \"python\": false, \"javascript\": false, \"typescript\": false, \"csharp\": false, \"c\": false, \"golang\": false, \"kotlin\": false, \"swift\": false, \"rust\": false, \"ruby\": false, \"php\": false, \"dart\": false, \"scala\": false, \"elixir\": false, \"erlang\": false, \"racket\": false, \"cangjie\": false, \"bash\": false, \"html\": false, \"pythonml\": false, \"react\": false, \"vanillajs\": false, \"mysql\": false, \"mssql\": false, \"postgresql\": false, \"oraclesql\": false, \"pythondata\": 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": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL 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 price_at_given_date(products: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"64.6K\", \"totalSubmission\": \"110.8K\", \"totalAcceptedRaw\": 64600, \"totalSubmissionRaw\": 110841, \"acRate\": \"58.3%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\":{\"Products\":[\"product_id\",\"new_price\",\"change_date\"]},\"rows\":{\"Products\":[[1,20,\"2019-08-14\"],[2,50,\"2019-08-14\"],[1,30,\"2019-08-15\"],[1,35,\"2019-08-16\"],[2,65,\"2019-08-17\"],[3,20,\"2019-08-18\"]]}}", "metaData": "{\"mysql\":[\"Create table If Not Exists Products (product_id int, new_price int, change_date date)\"],\"mssql\":[\"Create table Products (product_id int, new_price int, change_date date)\"],\"oraclesql\":[\"Create table Products (product_id int, new_price int, change_date date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"price_at_given_date\",\"pythondata\":[\"Products = pd.DataFrame([], columns=['product_id', 'new_price', 'change_date']).astype({'product_id':'Int64', 'new_price':'Int64', 'change_date':'datetime64[ns]'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Products (product_id int, new_price int, change_date date)\"],\"database_schema\":{\"Products\":{\"product_id\":\"INT\",\"new_price\":\"INT\",\"change_date\":\"DATE\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Products (product_id int, new_price int, change_date date)", "Truncate table Products", "insert into Products (product_id, new_price, change_date) values ('1', '20', '2019-08-14')", "insert into Products (product_id, new_price, change_date) values ('2', '50', '2019-08-14')", "insert into Products (product_id, new_price, change_date) values ('1', '30', '2019-08-15')", "insert into Products (product_id, new_price, change_date) values ('1', '35', '2019-08-16')", "insert into Products (product_id, new_price, change_date) values ('2', '65', '2019-08-17')", "insert into Products (product_id, new_price, change_date) values ('3', '20', '2019-08-18')" ], "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.2.2 and NumPy 1.26.4<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", "book": null, "isSubscribed": false, "isDailyQuestion": false, "dailyRecordStatus": null, "editorType": "CKEDITOR", "ugcQuestionId": null, "style": "LEETCODE", "exampleTestcases": "{\"headers\":{\"Products\":[\"product_id\",\"new_price\",\"change_date\"]},\"rows\":{\"Products\":[[1,20,\"2019-08-14\"],[2,50,\"2019-08-14\"],[1,30,\"2019-08-15\"],[1,35,\"2019-08-16\"],[2,65,\"2019-08-17\"],[3,20,\"2019-08-18\"]]}}", "__typename": "QuestionNode" } } }