Тёмный
Data Project Hub
Data Project Hub
Data Project Hub
Подписаться
🧑‍💻 Explaining the data, and analytics concepts I wish I had known earlier!

✌️Have a great day!
Комментарии
@AshishBusinessAnalyst-l7u
@AshishBusinessAnalyst-l7u 12 часов назад
Is this solution correct we have with cte as ( select *, COUNT(company) over (order by car_id)as aa from vehicle ) select *,FIRST_VALUE(company) over (partition by aa order by aa) from cte
@dataprojecthub
@dataprojecthub 15 часов назад
SQL Interview Bootcamp: Questions & Practice Exercises - ru-vid.com/group/PLRj6ORzjeGQ531TsgG_twzlY0796sVq1Z&si=DQ0Oci3r6qieUHgM
@dharmiklingam1108
@dharmiklingam1108 5 дней назад
Hi @Data Project Hub what about this code could tell me is this approch is right with cte as( select *,sum(weight_kg) over(partition by lift_id order by weight_kg) as total_sum from l) select lift_id,STRING_AGG(passenger_name,',')as passeneger_list from cte where lift_id=1 and total_sum <300 or lift_id =2 and total_sum <350 group by lift_id
@ChaitanyaKariya-x4q
@ChaitanyaKariya-x4q 6 дней назад
check this out! select lift_id, STRING_AGG(passenger_name, ', ' ORDER BY weight_kg ) AS aggregated_names_2 from ( select * from ( select *, sum(weight_kg) over(partition by lift_id order by weight_kg) as total_W from ( Select * from lift_passengers as L1 join lift as L2 on L1.Lift_id = L2.id)x)y where capacity_kg > total_W) z group by lift_id 😉
@chandanpatra1053
@chandanpatra1053 6 дней назад
Very good question.👍👍👍👍
@varunas9784
@varunas9784 7 дней назад
Thank you for sharing! here's my attempt on SQL server: ================================== with max_min as (select * from (select *, MAX(score) over(partition by exam_id order by exam_id) [Max score], MIN(score) over(partition by exam_id order by exam_id) [Min score] from exam) s1 where case when score > [Min score] and score < [Max score] then 'Y' else 'N' end = 'Y'), exam_no as (select student_id, COUNT(student_id) [num exams] from exam group by student_id) select distinct s.student_id, student_name from max_min m join exam_no e on m.student_id = e.student_id join student s on s.student_id = m.student_id where [num exams] >= 1 ==================================
@TirthJoshi-h3u
@TirthJoshi-h3u 7 дней назад
;WITH CTE AS ( SELECT *,ROW_NUMBER() OVER (partition by customer_id order by order_date) rn ,LAG(status,1) OVER(partition by customer_id order by order_date) lg_id ,LAG(order_date,1) OVER(partition by customer_id order by order_date) lg_id1 FROM customer_orders ) SELECT customer_id,DATEDIFF(DAY,lg_id1,order_date) as DaysTook FROM CTE WHERE lg_id IS NOT NULL and lg_id1 is not null and ((status='Delivered' and lg_id='Shipped')) and lg_id1<order_date
@chandanpatra1053
@chandanpatra1053 21 день назад
Very good question. Keep it up👍👍👍👍👍👍
@VenkateshMarupaka-gn3rp
@VenkateshMarupaka-gn3rp 27 дней назад
My Solution. WITH CTE AS (SELECT c.customer_id, c.customer_name, o.order_id, o.order_date, o.order_amount, MIN(order_date) OVER(PARTITION BY o.customer_id ORDER BY c.customer_id) AS first_order_date FROM customers c JOIN order_details o ON c.customer_id = o.customer_id) SELECT TOP 3 customer_id, customer_name, SUM(order_amount) AS total_amount FROM CTE WHERE month(order_date) = month(first_order_date) GROUP BY customer_id, customer_name ORDER BY total_amount DESC
@mayankchauhan5386
@mayankchauhan5386 27 дней назад
Thank for this example
@bankimdas9517
@bankimdas9517 29 дней назад
Thanks for sharing sir🙏
@dataprojecthub
@dataprojecthub 16 дней назад
Most welcome
@Arpitachakraborty1111
@Arpitachakraborty1111 Месяц назад
select distinct item from (select * , dense_rank() over (partition by item order by id ) as dn from items_table) x where dn >=3 i am getting the same output, is this correct method? please let me know
@ExcellentSycamore
@ExcellentSycamore Месяц назад
Garcia Ronald Jones Margaret Lee Joseph
@namangarg7023
@namangarg7023 Месяц назад
Also it can be done in cte only..u have used so many...
@vishalchakraborty2050
@vishalchakraborty2050 Месяц назад
You make it really easy to understand, Thank you 🙏
@dataprojecthub
@dataprojecthub 16 дней назад
Glad to hear that!
@harishsingh_424
@harishsingh_424 Месяц назад
You takes very good scenario based questions
@harishsingh_424
@harishsingh_424 Месяц назад
Nice
@dataprojecthub
@dataprojecthub 16 дней назад
Thanks
@sandydalhousie
@sandydalhousie Месяц назад
Thanks for the excellent explanation. I solved the same using this query: with cte as (select *, day(CreatedAt) as DAY_NO, coalesce(lag(day(CreatedAt)) over(partition by userId order by CreatedAt),0) as prev_DAY from Transactions_Ecomm), cte1 as (select *, case when (DAY_NO-prev_DAY)<=7 AND prev_DAY <> 0 AND DAY_NO <> prev_DAY then userId else null end as USERID_DIFFERENCE_IN_DAYS from cte) select DISTINCT userId from cte1 where userId=USERID_DIFFERENCE_IN_DAYS;
@bankimdas9517
@bankimdas9517 Месяц назад
Thanks for making this video
@sandydalhousie
@sandydalhousie Месяц назад
If I'm not wrong, isn't this a simpler way to solve this: WITH cte as (select *,LEAST(English,Maths,Science,Geography,History,Sanskrit) as LEAST_MARKS from exam) select *, (English+Maths+Science+Geography+History+Sanskrit-LEAST_MARKS)/5 as Output_Marks from cte;
@dataprojecthub
@dataprojecthub Месяц назад
Absolutely right! I went with a more flexible approach, and just a heads-up-these functions might not be available in every version of SQL Server.
@sandydalhousie
@sandydalhousie Месяц назад
@@dataprojecthub alright. Good to know that 👍🏽
@sravankumar1767
@sravankumar1767 Месяц назад
Superb explanation 👌 👏 👍
@chandramohan-bo5se
@chandramohan-bo5se Месяц назад
with cte as( select user_id_send,user_id_receiver_id , max(case when action='sent' then date end )as sent_date , max(case when action='recevied' then date end) as received_date from fb_friend_requests group by user_id_send,user_id_receiver_id) select sent_date ,count(sent_date) ,count(received_date )*1.0 / count(sent_date) *100 as percent_rate from cte group by sent_date
@Lokesh0595
@Lokesh0595 Месяц назад
Hey buddy Thanks for the videos Appreciating your honest efforts 🎉
@dataprojecthub
@dataprojecthub Месяц назад
My pleasure😀
@majeedadil777
@majeedadil777 Месяц назад
Thanks for sharing, really good stuff
@dataprojecthub
@dataprojecthub Месяц назад
Glad you enjoyed it🙂
@Apna_tahlka_123
@Apna_tahlka_123 Месяц назад
Agr bich bichme hindi mevbhi smjhado to jyada easy rhega or dekhne me bhi excitement rhegi 3:13
@sravankumar1767
@sravankumar1767 2 месяца назад
Superb explanation 👌 👏 👍
@dataprojecthub
@dataprojecthub Месяц назад
Glad you liked it😊
@ADFuser
@ADFuser 2 месяца назад
Thank you for the interview questions, And THANK YOU FROM BOTTOM OF MY HEART for providing the create table n insert table in the description
@dataprojecthub
@dataprojecthub Месяц назад
Glad you enjoyed it!😀
@powerbiuser
@powerbiuser 2 месяца назад
Sir, seeing such scenarios, am getting scared of SQL. how to learn all these advanced concepts from basics? :(
@dataprojecthub
@dataprojecthub Месяц назад
Learn and definitely you will be able to solve all such scenarios 😀 Learn basics and solve lot of questions.
@powerbiuser
@powerbiuser 2 месяца назад
you opened by eyes.. where can i get such interview questions...
@dataprojecthub
@dataprojecthub Месяц назад
You can find a lot of questions on my channel and if you want additional questions, please take a look at my github.👍
@KrishnaKarthik-t5r
@KrishnaKarthik-t5r 2 месяца назад
Waiting for next video
@chandanpatra1053
@chandanpatra1053 2 месяца назад
Bro atleast provide create & insert statement for the question you have discussed. No doubt , every time you bring valuable sql questions for the subscribers . But don't forget to add the create & insert statement in the description box.
@powerbiuser
@powerbiuser 2 месяца назад
yes please. do create create and insert, while practicing our tie is consumed by creating and inserting the data only..
@dataprojecthub
@dataprojecthub Месяц назад
I will be adding the table script for all upcoming videos. Thanks for the suggestion.😀
@vijaygupta7059
@vijaygupta7059 2 месяца назад
MY Solution in MSSQL : Select * from Students; with cte1 as ( Select * ,lead(Student_Name,1,Student_Name)over(order by ID) as rn_lead ,lag(Student_Name,1,Student_Name)over(order by ID) as rn_lag from Students ) Select ID , case when id%2=0 then rn_lag else rn_lead end as new from cte1
@prajwaladhav3297
@prajwaladhav3297 2 месяца назад
Hello there, in Q6 my answer is coming in 0 and 1 not in Yes or NO, what should I do
@MusicalShorts-hn1px
@MusicalShorts-hn1px 2 месяца назад
Amazed.....Learnt for sharing this problem with solution
@vijaygupta7059
@vijaygupta7059 2 месяца назад
thanks for the valuable question. I used your logic only. with r_cte as ( select char(65) as letter union all select char(ASCII(letter)+1) as letter from r_cte where letter < 'Z' ),n_cte as ( select 1 as num union all select num+1 as num from n_cte where num< 10 ),cte3 as ( Select letter, num, CONCAT(letter,num) as seat_id from n_cte cross join r_cte ) Select letter, STRING_AGG(seat_id,', ') as seat_id from cte3 group by letter
@bibhudas9329
@bibhudas9329 2 месяца назад
1 real life example of cross join . Thanks for sharing :)
@dataprojecthub
@dataprojecthub Месяц назад
My pleasure😀
@vijaygupta7059
@vijaygupta7059 3 месяца назад
Select * ,first_value(sales)over(partition by product order by id) as rn ,sum(sales)over(partition by product order by id) as rinning_total_sales from sales_tab order by id,product;
@Ilovefriendswebseries
@Ilovefriendswebseries 3 месяца назад
Please come up with difficult questions sir
@chetanvgoudar9079
@chetanvgoudar9079 3 месяца назад
im getting error alphabet table doesn't exist
@buddhikaperera5716
@buddhikaperera5716 3 месяца назад
lag and lead is work in sql 2008 version ?
@Ilovefriendswebseries
@Ilovefriendswebseries 3 месяца назад
with cte as( select *, lag(item,1) over(order by id ) laag, lead(item,1) over(order by id) leaad from items_table),cte2 as ( select *,case when item=laag then 1 when item= leaad then 1 else 0 end as flag from cte),cte3 as ( select distinct(item),flag,count(flag) over(partition by item) as cnt from cte2 where flag=1) select item from cte3 where cnt>=3
@Ilovefriendswebseries
@Ilovefriendswebseries 3 месяца назад
Another approach WITH cte AS ( SELECT *, COUNT(voter) OVER (PARTITION BY voter) AS voter_cnt, ROUND(1.0 / COUNT(voter) OVER (PARTITION BY voter), 3) AS vote_value FROM votes ) SELECT candidate,sum(vote_value) as total_votes from cte where candidate is not null group by candidate order by sum(vote_value) desc limit 1;
@Ilovefriendswebseries
@Ilovefriendswebseries 3 месяца назад
Here is my answer - can you tell me what you think of it with cte as ( SELECT emp_id, name, POWER(10,(5 - LENGTH(CAST(salary AS CHAR(50))))) * salary as newsal FROM emp_sal) select emp_id, name, newsal, avg(newsal) over() as avgsal from cte;
@vijaygupta7059
@vijaygupta7059 3 месяца назад
could you please ping insert and create command
@buddhikaperera5716
@buddhikaperera5716 3 месяца назад
thank you very much.. this help me a lot..
@dataprojecthub
@dataprojecthub Месяц назад
Glad it helped!
@vijaygupta7059
@vijaygupta7059 3 месяца назад
Thanks for explanation: I used your logic and solve little different method with rcte as ( Select min(start_date) as Date , max(end_date) as end_date from Tasks union all Select dateadd(day,1,Date) as Date, end_date from rcte where Date<end_date ) Select Date from rcte option(maxrecursion 3000);
@vijaygupta7059
@vijaygupta7059 3 месяца назад
Thanks for the explanation. ------------------------------ I used your method without cte Select value as words,count(*) as no_of_accurence from google_file_store cross apply string_split(contents,' ') where filename like 'draft%' group by value order by value
@vijaygupta7059
@vijaygupta7059 3 месяца назад
My solution in MSSQL DB: with cte1 as ( Select * ,row_number()over(partition by [group] order by sequence) as rn ,sequence - row_number()over(partition by [group] order by sequence) as rn1 from tab_sequence ) Select [group],min(sequence) as min_seq, max(sequence) as ma_seq from cte1 group by [group], rn1 order by [group]
@VenkateshMarupaka-gn3rp
@VenkateshMarupaka-gn3rp 3 месяца назад
My version of solution. WITH CTE AS (SELECT *, FIRST_VALUE(destination_phone_nbr) OVER(PARTITION BY source_phone_nbr ORDER BY source_phone_nbr) AS first_dest, LAST_VALUE(destination_phone_nbr) OVER(PARTITION BY source_phone_nbr ORDER BY source_phone_nbr) AS last_dest FROM phone_log) SELECT DISTINCT source_phone_nbr, CASE WHEN first_dest = last_dest THEN 'Y' ELSE 'N' END AS flag FROM CTE
@Ilovefriendswebseries
@Ilovefriendswebseries 3 месяца назад
Hi with cte as( select source_phone_nbr, destination_phone_nbr from phone_log where call_start_date_time=(select min(call_start_date_time) from phone_log ) ), cte2 as ( select source_phone_nbr, destination_phone_nbr from phone_log where call_start_date_time=(select max(call_start_date_time) from phone_log )), cte3 as( select * from cte union all select * from cte2) select source_phone_nbr ,case when count(*) >1 then 'y' ELSE 'n' END AS flag from cte3 group by source_phone_nbr ;