LeetCode 1565 Interview SQL Question with Detailed Explanation | Practice SQL

preview_player
Показать описание
Previous Video: LeetCode 1484 Group Sold Products by Date

In this video I solve and explain a leetcode SQL question using MySQL query. This question has been asked in Apple, Facebook, Amazon, Google, Adobe, Microsoft, Adobe interviews or what we popularly call FAANG interviews.
I explain the related concept as well. This question is about finding unique orders and customers per month and also includes points to keep in mind to develop SQL queries.

LeetCode is the best platform to help you enhance your skills, expand your knowledge and prepare for technical interviews.

If you found this helpful, Like and Subscribe to the channel for more content.

#LeetCodeSQL #FAANG #SQLinterviewQuestions
Рекомендации по теме
Комментарии
Автор

select left(order_date, 7) as month,
count( order_id ) as order_count,
count(distinct customer_id) as customer_count
from Orders
where invoice>20
group by left(order_date, 7)

mlvprasadofficial
Автор

great explanation sir thank you so much

dornalanavya
Автор

we also can use date_format(order_date, yyyy-mm) to group by

the_fury
Автор

CREATE TABLE Orders (
order_id INT,
order_date DATE,
customer_id INT,
invoice INT
);

INSERT INTO Orders (order_id, order_date, customer_id, invoice) VALUES
(1, '2020-09-15', 1, 30),
(2, '2020-09-17', 2, 90),
(3, '2020-10-06', 3, 20),
(4, '2020-10-20', 3, 21),
(5, '2020-11-10', 1, 10),
(6, '2020-11-21', 2, 15),
(7, '2020-12-01', 4, 55),
(8, '2020-12-03', 4, 77),
(9, '2021-01-07', 3, 31),
(10, '2021-01-15', 2, 20);

SELECT SUBSTRING(order_date, 1, 7) AS month, COUNT(*) AS order_count, COUNT(DISTINCT customer_id) AS customer_count
FROM Orders
WHERE invoice>20
GROUP BY SUBSTRING(order_date, 1, 7)

prathamsarraf