leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 42cde14c110d14f86d9e5a94034c10ff4d990485
parent 38732f4d6ae0accd7d912469820bf378d2d62916
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Mon,  7 Aug 2023 17:40:27 -0500

Completed product sales analysis iii

Diffstat:
Aproduct-sales-analysis-iii/product-sales-analysis-iii.sql | 11+++++++++++
1 file changed, 11 insertions(+), 0 deletions(-)

diff --git a/product-sales-analysis-iii/product-sales-analysis-iii.sql b/product-sales-analysis-iii/product-sales-analysis-iii.sql @@ -0,0 +1,11 @@ +--Write a sql query to return the first year +--of each product that has been sold along with +--the quantity and price of that year. + +SELECT s.product_id, s.year as first_year, s.quantity, s.price +FROM Sales s +WHERE (s.year, s.product_id) IN ( + SELECT MIN(s2.year), s2.product_id + FROM Sales s2 + GROUP BY s2.product_id +)