Loading...
「ツール」は右上に移動しました。
利用したサーバー: natural-voltaic-titanium
3いいね 33回再生

SQL Challenge: Find Unsold Products with High Stock Levels

🎯 SQL Scenario-Based Interview Question: Day 6
In this video, we solve a real-world SQL challenge: How to identify products with no sales in the last 6 months and excessive stock levels?

🔍 What You'll Learn:
✅ Using LEFT JOIN and WITH clauses to filter data.
✅ Calculating time-based conditions with DATEADD and GETDATE.
✅ Writing dynamic queries to solve inventory management problems.

👩‍💻 Who Is This Video For?
Perfect for Data Analysts, Data Engineers, Data Scientists, and anyone preparing for SQL job interviews!

📌 Topics Covered:

Filtering data with date conditions.
Combining inventory and sales data using LEFT JOIN.
Handling real-world scenarios with SQL.
🎯 Pro Tip: Optimize the query for large datasets by indexing date and product fields for better performance.

🔔 Subscribe for more SQL interview challenges tailored for all levels!

#sqlserver
#sqlquery
#whatissql
#sqldatabase
#oracle
#oraclesql
#SQLtutorialforbeginners
#learnSQLfromscratch
#SQLfromzerotohero
#SQLbasicstoadvanced
#SQLqueries
#SQLfordataanalysis
#SQLjoinsexplained
#SQLsubqueriestutorial
#SQLaggregationfunctions
#SQLinterviewquestions
#SQLrealworldexamples
#SQLmasterclass
#SQLtutorial2024
#learnSQLfast
#SQLfordatascience
#SQLbeginnertoexpert

drop table if exists Product
drop table if exists Sales
-- Create Product Table
CREATE TABLE Product (
ProductID INT PRIMARY KEY,
ProductName NVARCHAR(50),
StockLevel INT,
ReorderThreshold INT
);

-- Insert Data into Product Table
INSERT INTO Product VALUES
(1, 'Laptop', 30, 20),
(2, 'Mouse', 50, 40),
(3, 'Keyboard', 15, 10),
(4, 'Printer', 60, 50),
(5, 'Monitor', 20, 25);

-- Create Sales Table
CREATE TABLE Sales (
SaleID INT PRIMARY KEY,
ProductID INT,
SaleDate DATE
);

-- Insert Data into Sales Table
INSERT INTO Sales VALUES
(1, 1, DATEADD(MONTH, -3, GETDATE())), -- Sold in the last 6 months
(2, 2, DATEADD(MONTH, -2, GETDATE())), -- Sold in the last 6 months
(3, 3, DATEADD(MONTH, -6, GETDATE())), -- Boundary case: exactly 6 months
(4, 4, DATEADD(MONTH, -7, GETDATE())), -- Sold more than 6 months ago
(5, 5, DATEADD(MONTH, -8, GETDATE())); -- Sold more than 6 months ago

select * from Product
select * fro

コメント