Nishtha Nagar
Nishtha Nagar
  • Видео 54
  • Просмотров 73 128
Indium SQL Real-Interview Question | Medium Level | Important
In this video, we will solve an interesting SQL question where we need to identify numbers that appear at least three times consecutively in a table.
Script -
CREATE TABLE logs (
id INT PRIMARY KEY,
num INT
);
INSERT INTO logs (id, num) VALUES
(1, 1),
(2, 1),
(3, 1),
(4, 2),
(5, 1),
(6, 2),
(7, 2);
TIMESTAMP
00:00 Introduction
00:20 Problem Explanation
01:25 Solution Approach
02:27 Solution Steps
03:00 MySQL Solution
#sql #dataanalysts #dataengineer #dataanalysis #interviewquestion #sqlinterview #sqlinterviewquestions #sqlforbeginners
Просмотров: 971

Видео

McKinsey SQL Interview Question | Easy LevelMcKinsey SQL Interview Question | Easy Level
McKinsey SQL Interview Question | Easy Level
Просмотров 2,3 тыс.8 дней назад
Welcome to today’s SQL tutorial! In this video, we'll solve an interesting problem that involves finding the Net Present Value (NPV) for queries from two tables using SQL. Script - Table: npv CREATE TABLE npv ( id INT, year INT, npv DECIMAL(10, 2) ); INSERT INTO npv (id, year, npv) VALUES (1, 2018, 100), (7, 2020, 30), (13, 2019, 40), (1, 2019, 113), (2, 2008, 121), (3, 2009, 12), (11, 2020, 99...
Walmart SQL Interview Question | SQL Window Functions | AdvancedWalmart SQL Interview Question | SQL Window Functions | Advanced
Walmart SQL Interview Question | SQL Window Functions | Advanced
Просмотров 8 тыс.12 дней назад
In this video, we walk through a SQL query to retrieve Walmart users' most recent transaction date, user ID, and the total number of products they purchased. Learn how to efficiently sort data in chronological order and calculate product counts based on user transactions. Table: user_transactions CREATE TABLE transactions ( product_id INT, user_id INT, spend DECIMAL(10, 2), transaction_date DAT...
Zomato SQL Interview Question | Medium LevelZomato SQL Interview Question | Medium Level
Zomato SQL Interview Question | Medium Level
Просмотров 2,5 тыс.15 дней назад
In this Question, we will calculate the average rating for each restaurant for each month. We'll be using Zomato's review data to calculate the average rating for each restaurant on a monthly basis. Script - CREATE TABLE reviews ( review_id INT PRIMARY KEY, user_id INT, submit_date DATE, restaurant_id INT, rating INT ); INSERT INTO reviews (review_id, user_id, submit_date, restaurant_id, rating...
Spotify SQL Interview Question | Advanced SQLSpotify SQL Interview Question | Advanced SQL
Spotify SQL Interview Question | Advanced SQL
Просмотров 74418 дней назад
In this video, we’ll dive into an interesting SQL problem involving Spotify's music data. Our goal is to find the top 5 artists whose songs have appeared most frequently in the Top 10 of the global music charts. We’ll be using three tables: artists, songs, and global_song_rank. Find the Script of the tables here - Table: artists CREATE TABLE artists ( artist_id INT PRIMARY KEY, artist_name VARC...
IBM SQL Interview Question | Using CTEsIBM SQL Interview Question | Using CTEs
IBM SQL Interview Question | Using CTEs
Просмотров 2,2 тыс.23 дня назад
Learn how to find the details of employees having 3rd highest salary in each job_category. you Script - CREATE TABLE employees ( employee_id INT PRIMARY KEY, first_name VARCHAR(50), last_name VARCHAR(50), salary DECIMAL(10, 2), job_category VARCHAR(10) ); INSERT INTO employees (employee_id, first_name, last_name, salary, job_category) VALUES (101, 'John', 'Doe', 50000, 'DEV'), (102, 'Jane', 'Sm...
Swiggy SQL Interview Question | HackerRank AssessmentSwiggy SQL Interview Question | HackerRank Assessment
Swiggy SQL Interview Question | HackerRank Assessment
Просмотров 4,8 тыс.Месяц назад
In this video, we will solve a SQL question which has been asked in HackerRank Assessment by Swiggy. You're given order details and have to find out the count of delayed orders for each delivery partner. Script - CREATE TABLE order_details ( orderid INT PRIMARY KEY, custid INT, city VARCHAR(50), order_date DATE, del_partner VARCHAR(50), order_time TIME, deliver_time TIME, predicted_time INT, ao...
Target SQL Interview Question | Using Sub-query | Level - MEDIUMTarget SQL Interview Question | Using Sub-query | Level - MEDIUM
Target SQL Interview Question | Using Sub-query | Level - MEDIUM
Просмотров 4,2 тыс.Месяц назад
In this video, you would learn how to write a SQL query to identify sellers who did not make any sales in 2020. Script Table 1 - orders CREATE TABLE orders ( order_id INT PRIMARY KEY, sale_date DATE, order_cost DECIMAL(10, 2), customer_id INT, seller_id INT ); INSERT INTO orders (order_id, sale_date, order_cost, customer_id, seller_id) VALUES (1, '2020-03-01', 1500.00, 101, 1), (2, '2020-05-25'...
LinkedIn SQL Interview Question | Using CTEs | Advanced SQLLinkedIn SQL Interview Question | Using CTEs | Advanced SQL
LinkedIn SQL Interview Question | Using CTEs | Advanced SQL
Просмотров 1,7 тыс.Месяц назад
In this video, we will solve a question that involves working with a table named job_listings, which contains job postings from various companies on LinkedIn. The objective is to write a SQL query that identifies and counts the number of companies that have posted duplicate job listings. ( Note: Duplicate job Listings are those job postings that are from the same company (company_id) that have ...
Zomato SQL Interview Question | Using CTEs | Advanced SQLZomato SQL Interview Question | Using CTEs | Advanced SQL
Zomato SQL Interview Question | Using CTEs | Advanced SQL
Просмотров 12 тыс.Месяц назад
In this video, we'll solve an advanced SQL challenge: correcting a swapping error in Zomato's order database. Imagine each order's item has been mistakenly swapped with the next-our task is to use Common Table Expressions (CTEs) to realign the order IDs with the correct items. Follow along as we solve this problem step-by-step and ensure data integrity. Script CREATE TABLE orders ( order_id INT...
Top 7 Data Analysis Methods You Must KnowTop 7 Data Analysis Methods You Must Know
Top 7 Data Analysis Methods You Must Know
Просмотров 241Месяц назад
This video covers the "Top 7 Data Analysis Methods You Must Know" to help you elevate your data skills and make data-driven decisions with confidence. #dataanalysts #dataanalysis #data #datascience #education #sql #sqltips #dataanalytics #programming #sqlforbeginners #sqlinterviewquestions #sqlinterviewquestionsandanswers TIMESTAMP 00:00 Introduction 00:15 Types of Data Analysis Methods 00:37 E...
SQL Query Writing and Execution Order | SQL TutorialSQL Query Writing and Execution Order | SQL Tutorial
SQL Query Writing and Execution Order | SQL Tutorial
Просмотров 251Месяц назад
Learn the exact order in which SQL processes your commands, from fetching data to final results. Master query optimization and troubleshoot errors like a pro. TIMESTAMP 00:00 Introduction 00:22 SQL Query Writing Order 02:05 SQL Query Execution Order 03:31 Example #sql #sqlserver #sqlforbeginners #sqltips #dataanalysis #dataanalysts #education #sqlqueryinterviewquestionsandanswers #jobinterview ...
Amazon SQL Interview Question | SQL Advanced | Window Functions in SQLAmazon SQL Interview Question | SQL Advanced | Window Functions in SQL
Amazon SQL Interview Question | SQL Advanced | Window Functions in SQL
Просмотров 1,6 тыс.2 месяца назад
In this video, we will solve an advanced SQL problem asked in Amazon Interviews. Given the details of the Amazon customer, specifically focusing on the 'product_spend' table, which contains information about customer purchases, the products they bought, and how much they spent. You need to find the top two highest-selling products within each category based on total spending. This problem will ...
Uber SQL Interview Question | Find User's third transaction | SQL Window Functions | Advanced SQLUber SQL Interview Question | Find User's third transaction | SQL Window Functions | Advanced SQL
Uber SQL Interview Question | Find User's third transaction | SQL Window Functions | Advanced SQL
Просмотров 2,7 тыс.2 месяца назад
Learn how to find a user's third transaction using SQL window functions. This video breaks down the problem step-by-step, providing a clear and concise solution. Master advanced SQL techniques and impress your interviewers! Script - CREATE TABLE transactions ( user_id INT, spend DECIMAL(10,2), transaction_date DATETIME ); INSERT INTO transactions (user_id, spend, transaction_date) VALUES (111, ...
Microsoft SQL Interview Question | Find Supercloud Customer | SQL Window Function | Advanced SQLMicrosoft SQL Interview Question | Find Supercloud Customer | SQL Window Function | Advanced SQL
Microsoft SQL Interview Question | Find Supercloud Customer | SQL Window Function | Advanced SQL
Просмотров 2,2 тыс.2 месяца назад
In this video, we'll solve a Microsoft SQL problem: identifying "Supercloud" customers. These are customers who have purchased at least one product from every product category available. We'll break down the solution step-by-step, exploring the data structure and the SQL query used to achieve this. Given two tables - customer_contracts and products table - 1. customer_contracts table records ea...

Комментарии

  • @prajju8114
    @prajju8114 9 часов назад

    solution using pyspark from pyspark.sql.window import Window win=Window.partitionBy('user_id').orderBy(col('transaction_date').desc()) walmart_df=walmart_df.withColumn('rank',rank().over(win)) walmart_df=walmart_df.where(col('rank')==1) walmart_df1=walmart_df.groupBy('user_id','transaction_date').agg(count('*').alias('purchase_count')).orderBy(col('transaction_date')) walmart_df1.show(truncate=False)

  • @arjundev4908
    @arjundev4908 9 часов назад

    with cte as(SELECT *, dense_rank()over(partition by user_id order by transaction_date desc) as rw FROM transactions) select transaction_date,user_id,count(distinct product_id) as purchase_count from cte where rw = 1 group by 1,2;

  • @ishitvasingh9902
    @ishitvasingh9902 10 часов назад

    We can also approach this by using Max agg function as a window function in cte and then call it out, with cte as ( select * , max(transaction_date) over (partition by user_id order by user_id) as recent_date from transactions) select transaction_date, user_id, count(product_id) as product_count from cte where transaction_date = recent_date group by 1,2 order by 1,2

  • @ishitvasingh9902
    @ishitvasingh9902 11 часов назад

    Nicely explained video. I have an approach with more advanced funtions i.e, lead and lag, SELECT order_id, CASE WHEN order_id % 2 = 1 THEN COALESCE(lead(item) over (ORDER BY order_id), item) ELSE lag(items) over (ORDER BY order_id) END AS item FROM orders

  • @samyukthashanmugam7516
    @samyukthashanmugam7516 12 часов назад

    WITH cte AS ( SELECT user_id, spend, transaction_date, ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY transaction_date ASC) AS user_trans FROM transactions ) SELECT * FROM cte WHERE user_trans = 3 ORDER BY user_id;

  • @rk-ej9ep
    @rk-ej9ep 15 часов назад

    Nice..Thanks for your efforts..

  • @vaibhavyadav2499
    @vaibhavyadav2499 19 часов назад

    SELECT num AS consecutive_nums FROM logs GROUP BY num HAVING COUNT(DISTINCT id) >=3 AND MAX(id) - MIN(id) =2;

  • @rohit_vora
    @rohit_vora День назад

    postgresql : with cte as (select *, (id - row_number() over(partition by cnt order by id )) rn from (select * ,count(*) over(partition by num order by id range between unbounded preceding and unbounded following) cnt from logs)) select distinct num from (select *, count(rn) over(partition by rn order by id range between unbounded preceding and unbounded following) final_cnt from cte) where final_cnt >=3

  • @badrilalnagar9232
    @badrilalnagar9232 День назад

    God's love is reserved only for the virtuous and the dutiful.

  • @TriggerJigar
    @TriggerJigar День назад

    Please make video on SQL in detail

  • @kalyantamiri8878
    @kalyantamiri8878 2 дня назад

    SELECT TRANSACTION_DATE ,USER_ID,COUNT(PRODUCT_ID) PURCHASE_COUNT FROM ( SELECT PRODUCT_ID,USER_ID,TRANSACTION_DATE, DENSE_RANK() OVER(PARTITION BY USER_ID ORDER BY USER_ID,TRANSACTION_DATE DESC) RN FROM transactions) WHERE RN=1 GROUP BY USER_ID, TRANSACTION_DATE;

  • @yamanthakur7352
    @yamanthakur7352 2 дня назад

    I tried through subqueries and 2 possible solutions: sol1: select ROW_NUMBER() Over(partition by user_id order by user_id asc) Rn, user_id,count(product_id) productCount, transaction_date from transactions Where transaction_date IN(select MAX(transaction_date) from transactions group by user_id ) group by user_id, transaction_date -------------------------------------------------------------------------------------- sol2: select * from (select RANK() OVER(Partition by user_id Order by transaction_date desc) RANK, user_id,count(product_id) prodcount, transaction_date from transactions group by user_id,transaction_date) TN Where TN.RANK=1

  • @KapilKumar-hk9xk
    @KapilKumar-hk9xk 2 дня назад

    with cte as (select *, dense_rank() over(partition by user_id order by date(transaction_date) desc) as dr from transactions) select transaction_date, user_id, count(product_id) as purchase_count from cte where dr = 1 group by transaction_date, user_id;

  • @ShobhitSharma-hq7tz
    @ShobhitSharma-hq7tz 2 дня назад

    This question asked for fresher or experience

  • @user-gq6cg3ls7f
    @user-gq6cg3ls7f 2 дня назад

    with cte as( select *, LAG(num) over (order by id) pre_row, LEAD(num) over (order by id) next_row from logs ) select num as consecutive_number from cte where (num=pre_row) and (pre_row=next_row)

  • @hairavyadav6579
    @hairavyadav6579 3 дня назад

    Please mam ,, Bring one project on real scenario based , with 15 questions ..

  • @hairavyadav6579
    @hairavyadav6579 3 дня назад

    select distinct l1.num from logs l1 join logs l2 on l1.id=l2.id-1 join logs l3 on l1.id=l3.id-2 where l1.num = l2.num and l2.num = l3.num;

  • @hairavyadav6579
    @hairavyadav6579 3 дня назад

    My approach select distinct num from (select *,lead(num) over(order by id) as l1 , lead(num,2) over(order by id) as l2 from logs) sal where num = l1 and l1=l2;

  • @anshusharaf2019
    @anshusharaf2019 3 дня назад

    WITH cte AS ( SELECT id, num, LEAD(num) OVER(ORDER BY id) AS next_num FROM logs ), cte2 AS ( SELECT num, (next_num - num) AS diff FROM cte ) SELECT num, COUNT(diff) AS cnt FROM cte2 WHERE diff IS NOT NULL GROUP BY num; My approach little bit different I used only CTE's and Count(), group By

  • @amanrawat7894
    @amanrawat7894 3 дня назад

    Thoda bhut Hindi language use kar doge sarkar??😅

  • @dhruvdhandhukiya8027
    @dhruvdhandhukiya8027 3 дня назад

    select a.transaction_date, a.user_id, a.purchase_count from ( select transaction_date, user_id, count(product_id) as purchase_count, max(transaction_date) over (partition by user_id) as max_transaction_date from transactions_new group by (transaction_date), user_id order by transaction_date ) a where transaction_date = max_transaction_date

  • @humdrum2041
    @humdrum2041 3 дня назад

    Hi is there any way you could do that without creating those extra tables?

  • @nishchaljain9351
    @nishchaljain9351 3 дня назад

    Another approach to solve it is as below.. select Num as consecutive_num from ( select *, LEAD(Num,1,Num) over(order by id) as next_num, LEAD(Num,2) over(order by id) as next_to_next_num, case when Num = LEAD(Num,1,Num) over(order by id) and Num = LEAD(Num,2) over(order by id) then 1 else 0 end as flag from Logs ) x where x.flag = 1

  • @aditi_shetti
    @aditi_shetti 3 дня назад

    My take on the question where I have used dense_rank instead of row_number with cte1 as ( select user_id, spend, transaction_date , dense_rank() over(partition by user_id order by transaction_date) as dense_rn from transactions_1 ) select user_id, spend, transaction_date from cte1 where dense_rn = 3

  • @Savenature635
    @Savenature635 3 дня назад

    with cte as (select distinct a.artist_name,s.artist_id,count(g.song_id) as number_of_appearances from artists a join songs s on a.artist_id=s.artist_id join global_song_rank g on s.song_id=g.song_id where g.rankk<=10 group by 1,2),cte_2 as ( select *,dense_rank() over(order by number_of_appearances desc) as artist_rank from cte) select artist_name,artist_rank from cte_2 where artist_rank<=5;

  • @Savenature635
    @Savenature635 3 дня назад

    My approach in MySql : with cte as (select *,month(submit_date) as monthh,count(rating) over(partition by month(submit_date),restaurant_id) as count_rating from reviews) select monthh,restaurant_id, round((sum(rating))/(count(rating)),1) as average_rating from cte where count_rating>=2 group by 1,2 order by restaurant_id,monthh;

  • @yashmehta6920
    @yashmehta6920 4 дня назад

    It's my solution which is lengthy compared to video explanation just because of i don't know about TIMESTAMPDIFF function WITH cte3 AS ( SELECT *, HOUR(TIME(deliver_time - order_time)) * 60 + MINUTE(TIME(deliver_time - order_time)) AS Actual_time FROM order_details ), cte4 AS ( SELECT *, CASE WHEN Actual_time > predicted_time THEN 'Delayed' ELSE 'On Time' END AS delivery_cat FROM cte3 ) SELECT del_partner, COUNT(delivery_cat) FROM cte4 WHERE delivery_cat = 'Delayed' GROUP BY del_partner; Please give feedback if you like..

  • @HimanshuSingh-cf7wr
    @HimanshuSingh-cf7wr 4 дня назад

    with m as ( select dense_rank() over (partition by user_id order by transaction_date desc) as ds_rnk, km.* from transactions as km) select distinct transaction_date,user_id,count(product_id) over (partition by user_id) as purchase_count from m where ds_rnk=1

  • @SQLBUDDYJOB
    @SQLBUDDYJOB 4 дня назад

    with cte as ( select category,PRODUCT, sum(spend) as total_spend from ProductSpend group by category,PRODUCT ---order by category,PRODUCT ), cte2 as ( select *, RANK() over(partition by category order by total_spend desc) as rankings from cte ) select category,PRODUCT,total_spend from cte2 where rankings in (1,2)

  • @SQLBUDDYJOB
    @SQLBUDDYJOB 4 дня назад

    select count(company_id) as duplicate_companies from ( select company_id, title, description,count(*) as cnt from job_listings group by company_id, title, description) tbl where tbl.cnt >1

  • @echodelta7680
    @echodelta7680 5 дней назад

    Suppose there are two tables A and B. Each table has only two columns, ID and NAME. We have to get an output table that has rows in it as : 1st row from A 1st row from B 2nd row from A 2nd row from B 3rd row from A 3rd row from B .... and so on. What would be the query to generate this output table ?

  • @badrilalnagar9232
    @badrilalnagar9232 5 дней назад

    According to the discovery of scientists, the most amazing thing in the universe is the human brain.

  • @SQLBUDDYJOB
    @SQLBUDDYJOB 5 дней назад

    here is my solution : select seller_name from sellers where seller_name not in ( select s.seller_name as sellername from orders o join sellers s on o.seller_id = s.seller_id and Year(o.sale_date) =2020 group by s.seller_name )

  • @vinil9212
    @vinil9212 5 дней назад

    change varchar 255 to in 25 in case your output is weird: with cte as ( select order_id, lead(item,1,item) OVER(order by order_id) as lead_item, lag(item) OVER(order by order_id) as lag_item from orders) select order_id, case when order_id%2=0 then lag_item else lead_item end as item from cte;

  • @amitjangid3471
    @amitjangid3471 5 дней назад

    select month(submit_date) as month, restaurant_id, format(avg(rating*1.0),'0.0') as avg_rating from reviews group by month(submit_date), restaurant_id having count(review_id) >=2

  • @SQLBUDDYJOB
    @SQLBUDDYJOB 6 дней назад

    here is my solution : with cte as ( select * , cast(DATEDIFF(Minute, order_time,deliver_time) as int) as actual_time from order_details ),cte2 as( select * , case when actual_time>predicted_time then 1 else 0 end as flag from cte ) select del_partner, count(*) as order_count from cte2 where flag =1 group by del_partner

  • @echodelta7680
    @echodelta7680 6 дней назад

    What is the order of processing in following line? DENSE_RANK() OVER(PARTITION BY department ORDER BY salary DESC) Does the partitioning of departments happen first, followed by ordering of salaries within those partitions and finally ranking of rows? Or does it happen in some other order? Kindly enlighten.

  • @DataToInfo
    @DataToInfo 6 дней назад

    In dataset, the column name is 'order_date' not 'date'. Anyway, good example.

  • @echodelta7680
    @echodelta7680 6 дней назад

    Hi Nishtha, 1. If there are more than 1 employee in each dept. having same salary as third highest salary, then what result would your query return? 2. Say, there is a table TRANSACTION having two columns ID and BILL. Table has 100 records, with IDs repeated many times, each ID having different or same bills. Here's a SELECT query to find the avg. bill for each ID over the table : SELECT ID, AVG(BILL) FROM TRANSACTION GROUP BY ID; My question is, does the AVG function run 100 x 100 times, top to bottom scanning one ID at a time? Note that I am not asking about the order of query execution (I know the order). I'm asking how these functions operate on the table rows in the background.

  • @rohit_vora
    @rohit_vora 6 дней назад

    select customer_id, count(product_category) cnt from customer_contracts cc join products p on p.product_id = cc.product_id group by 1 having count(product_category) = (select count(distinct category) totl_ctgry from products)

  • @rohit_vora
    @rohit_vora 6 дней назад

    with cte as (select artist_name, count(1) cnt from (select artist_name, s.song_id , a.artist_id, rank from artists a join songs s on s.artist_id = a.artist_id join global_song_rank gr on gr.song_id = s.song_id where rank <= 10) x group by 1) select artist_name , dense_rank() over(order by cnt desc) rnk from cte

  • @rohit_vora
    @rohit_vora 6 дней назад

    select restaurant_id, mnt, round(avg(rating),1) avgs from (select *, extract(month from submit_date) mnt from reviews) x group by 1,2 having count(rating) >= 2 order by 2,1

  • @1112electronics
    @1112electronics 6 дней назад

    Great video and awesome explanation..thanks .. keep it up...🎉

  • @MasoodKazi-sx6el
    @MasoodKazi-sx6el 6 дней назад

    thank you amazing explanation

  • @manjunathbukkapatnam3731
    @manjunathbukkapatnam3731 6 дней назад

    Hi @nishitha Nagar Can you please also post the create and insert script for the scenario based questions

  • @shgg5996
    @shgg5996 6 дней назад

    SELECT transaction_dt, user_id, COUNT(product_id) AS product_count FROM user_transaction GROUP BY transaction_dt, user_id ORDER BY transaction_dt DESC LIMIT 1;

  • @SQLBUDDYJOB
    @SQLBUDDYJOB 7 дней назад

    Here is my solution with cte as( select tbl.artist_id,a.artist_name, count(*) as cnt from artists a join ( select s.song_id,s.artist_id from global_song_rank gl join songs s on gl.song_id = s.song_id and gl.rank <=10 --order by s.artist_id ) tbl on a.artist_id = tbl.artist_id group by tbl.artist_id,a.artist_name ) select *, DENSE_RANK() over(order by cnt desc) as rank from cte

  • @hairavyadav6579
    @hairavyadav6579 7 дней назад

    Nice explanation ,,

  • @rohit_vora
    @rohit_vora 7 дней назад

    in postgresql: with cte as (select * ,(start_date - lag(start_date,1, start_date-1) over(order by task_id)) flag from project), flags as (select * ,(sum(flag) over(order by task_id) - task_id) grp from cte), final as (select distinct min(start_date) over(partition by grp ) start_date, max(end_date) over(partition by grp ) end_date, (max(end_date) over(partition by grp ) -min(start_date) over(partition by grp ) ) date_diff from flags) select start_date, end_date from final order by date_diff

  • @vijaygupta7059
    @vijaygupta7059 7 дней назад

    Select q.*, case when n.npv is not null then n.npv else 0 end as npv from queries as q left join npv as n on q.id=n.id and q.year=n.year