2023-12-09 18:53:53 +08:00
{
"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" : "<p>Table: <code>Products</code></p>\n\n<pre>\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.</pre>\n\n<p> </p>\n\n<p>Write a solution to find the prices of all products on <code>2019-08-16</code>. Assume the price of all products before any change is <code>10</code>.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+------------+-----------+-------------+\n<strong>Output:</strong> \n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2 | 50 |\n| 1 | 35 |\n| 3 | 10 |\n+------------+-------+\n</pre>\n" ,
"translatedTitle" : "指定日期的产品价格" ,
"translatedContent" : "<p>产品数据表: <code>Products</code></p>\n\n<pre>\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这张表的每一行分别记录了 某产品 在某个日期 更改后 的新价格。</pre>\n\n<p> </p>\n\n<p>编写一个解决方案,找出在 <code>2019-08-16</code><strong> </strong>时全部产品的价格,假设所有产品在修改前的价格都是 <code>10</code><strong> 。</strong></p>\n\n<p>以 <strong>任意顺序 </strong>返回结果表。</p>\n\n<p>结果格式如下例所示。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2 | 50 |\n| 1 | 35 |\n| 3 | 10 |\n+------------+-------+</pre>\n" ,
"isPaidOnly" : false ,
"difficulty" : "Medium" ,
"likes" : 149 ,
"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}" ,
"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 price_at_given_date(products: pd.DataFrame) -> pd.DataFrame:\n " ,
"__typename" : "CodeSnippetNode"
} ,
{
"lang" : "PostgreSQL" ,
"langSlug" : "postgresql" ,
"code" : "-- Write your PostgreSQL query statement below" ,
"__typename" : "CodeSnippetNode"
}
] ,
2023-12-09 19:57:46 +08:00
"stats" : "{\"totalAccepted\": \"24.7K\", \"totalSubmission\": \"44.2K\", \"totalAcceptedRaw\": 24695, \"totalSubmissionRaw\": 44232, \"acRate\": \"55.8%\"}" ,
2023-12-09 18:53:53 +08:00
"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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}