{ "data": { "question": { "questionId": "1278", "questionFrontendId": "1164", "boundTopicId": null, "title": "Product Price at a Given Date", "titleSlug": "product-price-at-a-given-date", "content": "
Table: Products
\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
\n\n
Write a solution to find the prices of all products on 2019-08-16
. Assume the price of all products before any change is 10
.
Return the result table in any order.
\n\nThe 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": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Medium", "likes": 709, "dislikes": 179, "isLiked": null, "similarQuestions": "[]", "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\"]]}}", "categoryTitle": "Database", "contributors": [], "topicTags": [ { "name": "Database", "slug": "database", "translatedName": null, "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below\n", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */\n", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */\n", "__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\n", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"77K\", \"totalSubmission\": \"137.8K\", \"totalAcceptedRaw\": 77042, \"totalSubmissionRaw\": 137775, \"acRate\": \"55.9%\"}", "hints": [], "solution": { "id": "1621", "canSeeDetail": true, "paidOnly": false, "hasVideoSolution": false, "paidOnlyVideo": true, "__typename": "ArticleNode" }, "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, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"mysql\": [\"MySQL\", \"
MySQL 8.0
.
mssql server 2019
.
Oracle Sql 11.2
.
Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0
\"], \"postgresql\": [\"PostgreSQL\", \"PostgreSQL 16
\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }