#SQL

Published: 05 October 2024
on channel: The Code Samples
202
18

#SQL Leetcode SQL 50 #25: 1070:

Write a solution to select the product id, year, quantity, and price for the first year of every product sold.
Return the resulting table in any order.

We will be solving all the questions from LeetCode SQL 50 one by one. These questions range from easy to hard.

**SQL scripts you can use to create and populate the table:
-- Create the sales table
CREATE TABLE sales (
sale_id INT,
product_id INT,
year INT,
quantity INT,
price DECIMAL(10, 2)
);

-- Insert data into the sales table
INSERT INTO sales (sale_id, product_id, year, quantity, price) VALUES
(1, 100, 2008, 10, 5000),
(2, 100, 2009, 12, 5000),
(7, 200, 2011, 15, 9000);

-- Create the product table
CREATE TABLE product (
product_id INT,
product_name VARCHAR(50)
);

-- Insert data into the product table
INSERT INTO product (product_id, product_name) VALUES
(100, 'Nokia'),
(200, 'Apple'),
(300, 'Samsung');

#datascience #coding #programming #mssql #databasemanagement #leetcode #leetcode1070 #leetcodesolution

👉SQL Tutorials Playlist:
   • SQL Tutorials  

👉SQL Shorts Playlist:
   • SQL Shorts  

👉Python Shorts Playlist:
   • Playlist  

👉Python Tutorials Playlist:
   • Python Tutorials  

👉Excel Shorts Playlist:
   • Excel Shorts  


Watch video #SQL online without registration, duration hours minute second in high quality. This video was added by user The Code Samples 05 October 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 202 once and liked it 18 people.