Product Price at a Given Date | Leetcode 1164 | Crack SQL Interviews in 50 Qs #mysql #leetcode

preview_player
Показать описание
Want to crack SQL interviews? Check out our latest video!!!

A 50-questions SQL study plan to ace any interview.
This tutorial will walk you through the solution in easy steps. This is an easy-level question from Leetcode.

Consistency is what transforms average into excellence.
So be consistent & keep Coding💻!!

Timecodes
0:00 - Introduction
0:29 - Question Explanation
2:15 - Understanding Concept with the help of Example
5:57 - Writing SQL Query
9:42 - Explanation of SQL Query
11:18 - Outro

Connect With Me -

#coding
#leetcode
#mysql
#sql
#interview
#sqlinterview
#sqlinterviewquestionsandanswers
#sql_server
#learnwithchirag
#product
#price
#data
Рекомендации по теме
Комментарии
Автор

Hey there! 👋 For more interesting content, tutorials, and updates, Feel free to connect with me on

Instagram Handles :-



Let's stay connected and keep the creativity flowing! 💡

learnwithchirag
Автор

A good question on Union, take me alot of time, fabulous explaination!

nimbu_
Автор

Thank you bhaiya, very nice explanation !

Apoorv_Pradhan
Автор

Sir, the syntax you are using is for MYSQL or POSTGRESQL?

supriyakashyap
Автор

Hi Chirag
select
t.product_id,
CASE
WHEN t.change_date = '2019-08-16' THEN t.new_price
WHEN t.change_date < '2019-08-16' THEN t.new_price
ELSE 10
END AS price
FROM (
SELECT
product_id,
new_price,
change_date,
ROW_NUMBER() OVER (PARTITION BY product_id ORDER BY change_date) AS rt
FROM
products
) AS t
group by t.product_id;
why is this query not working fine?

poorvamahto
Автор

select
product_id,
price
from
(select
product_id,
price,
row_number() over(partition by product_id order by change_date) as rnk
from
((select product_id,
new_price as price,
change_date
from Products
where (product_id, change_date) IN
(select product_id,
max(change_date)
from Products
where change_date <= '2019-08-16'
group by product_id))
union
(select product_id,
10 as price,
change_date
from Products
where product_id not in
(select product_id
where change_date <= '2019-08-16'))) sub) query
where query.rnk = 1

krishnabohidar
Автор

# Write your MySQL query statement below
select product_id, new_price as price
from products
where (product_id, change_date) IN
(
select product_id, max(change_date)
from product
where change_date <= '2019-08-16'
group by product_id
)
UNION

select product_id, 10 as price
from products
where product_id NOT IN
(
select prouduct_id
from products
where change_date <= '2019-08-16'
)
;
whats wrong in this code? its showing run time error.

nikkhiliitbhu
join shbcf.ru