mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-12 17:05:15 +08:00
update
This commit is contained in:
@@ -12,32 +12,25 @@
|
||||
+-------------+-------+
|
||||
(sale_id, year) is the primary key (combination of columns with unique values) of this table.
|
||||
product_id is a foreign key (reference column) to <code>Product</code> table.
|
||||
Each row of this table shows a sale on the product product_id in a certain year.
|
||||
Note that the price is per unit.
|
||||
Each row records a sale of a product in a given year.
|
||||
A product may have multiple sales entries in the same year.
|
||||
Note that the per-unit price.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p>Write a solution to find all sales that occurred in the <strong data-end="967" data-start="953">first year</strong> each product was sold.</p>
|
||||
|
||||
<p>Table: <code>Product</code></p>
|
||||
<ul data-end="1234" data-start="992">
|
||||
<li data-end="1078" data-start="992">
|
||||
<p data-end="1078" data-start="994">For each <code data-end="1015" data-start="1003">product_id</code>, identify the earliest <code data-end="1045" data-start="1039">year</code> it appears in the <code data-end="1071" data-start="1064">Sales</code> table.</p>
|
||||
</li>
|
||||
<li data-end="1140" data-start="1079">
|
||||
<p data-end="1140" data-start="1081">Return <strong data-end="1095" data-start="1088">all</strong> sales entries for that product in that year.</p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<pre>
|
||||
+--------------+---------+
|
||||
| Column Name | Type |
|
||||
+--------------+---------+
|
||||
| product_id | int |
|
||||
| product_name | varchar |
|
||||
+--------------+---------+
|
||||
product_id is the primary key (column with unique values) of this table.
|
||||
Each row of this table indicates the product name of each product.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write a solution to select the <strong>product id</strong>, <strong>year</strong>, <strong>quantity</strong>, and <strong>price</strong> for the <strong>first year</strong> of every product sold.</p>
|
||||
|
||||
<p>Return the resulting table in <strong>any order</strong>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
<p data-end="1234" data-start="1143">Return a table with the following columns: <strong>product_id</strong>,<strong> first_year</strong>, <strong>quantity, </strong>and<strong> price</strong>.<br />
|
||||
Return the result in any order.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
@@ -52,14 +45,7 @@ Sales table:
|
||||
| 2 | 100 | 2009 | 12 | 5000 |
|
||||
| 7 | 200 | 2011 | 15 | 9000 |
|
||||
+---------+------------+------+----------+-------+
|
||||
Product table:
|
||||
+------------+--------------+
|
||||
| product_id | product_name |
|
||||
+------------+--------------+
|
||||
| 100 | Nokia |
|
||||
| 200 | Apple |
|
||||
| 300 | Samsung |
|
||||
+------------+--------------+
|
||||
|
||||
<strong>Output:</strong>
|
||||
+------------+------------+----------+-------+
|
||||
| product_id | first_year | quantity | price |
|
||||
|
Reference in New Issue
Block a user