#SQL

Опубликовано: 31 Декабрь 2024
на канале: 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