A Good SQL Problem Based on Bank Transactions Asked in Visa Interview

Ғылым және технология

In this video we are going to discuss a SQL problem asked in Visa interview. We will solve it step by step. You can practice the problem here:
datalemur.com/questions/sql-m...
Zero to hero(Advance) SQL Aggregation:
• All About SQL Aggregat...
Most Asked Join Based Interview Question:
• Most Asked SQL JOIN ba...
Solving 4 Trick SQL problems:
• Solving 4 Tricky SQL P...
Data Analyst Spotify Case Study:
• Data Analyst Spotify C...
Top 10 SQL interview Questions:
• Top 10 SQL interview Q...
Interview Question based on FULL OUTER JOIN:
• SQL Interview Question...
Playlist to master SQL :
• Complex SQL Questions ...
Rank, Dense_Rank and Row_Number:
• RANK, DENSE_RANK, ROW_...
#sql #visa #interview

Пікірлер: 72

  • @Anonymous-en4fo
    @Anonymous-en4fo Жыл бұрын

    Hi Ankit, I’ve been following your channel since a long time and I’ve practiced almost every SQL question that you’ve uploaded. Last month I had a Data Engineer interview with Amazon, they asked me 5 SQL questions and you have uploaded 4 of them! Next Monday will be my first day at Amazon :) Thank you so much! I’m truly grateful to you! Hope you achieve everything that you want in life.

  • @jparmar1

    @jparmar1

    Жыл бұрын

    Apna interview experience bataiye na. Data structures and algos bhi they ?

  • @HarishKumar-sh3bn

    @HarishKumar-sh3bn

    Жыл бұрын

    Where you learned big data / data engineering?

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Thats brilliant. Keep shining 🌟🌟

  • @khushahmed97

    @khushahmed97

    Жыл бұрын

    It’ll be helpful if you share your experience , or your linkedin id

  • @ankit9531

    @ankit9531

    Жыл бұрын

    Same comment everywhere from linkedin to youtube 🤣🤣

  • @kumarrohit4994
    @kumarrohit4994 Жыл бұрын

    Hi Ankit hats off to your work amazing topics and questions you are covering. Very helpful channel. Thankyou for your KZread videos.

  • @amanahmed6057
    @amanahmed6057 Жыл бұрын

    Thanks for introducing Data Lamur to us

  • @prikshitbatta
    @prikshitbatta Жыл бұрын

    Really masterclass Ankit!

  • @tusharchhabra5022
    @tusharchhabra5022 Жыл бұрын

    insightful solution

  • @vandanaK-mh9zo
    @vandanaK-mh9zo6 ай бұрын

    My Approach to the question (using concepts learned in your earlier videos): with cte as ( select transaction_id, type, to_date(transaction_date) transaction_date, sum(case when type='withdrawal' then amount*-1 else amount end) over (order by transaction_date rows between unbounded preceding and current row) as run_sum, row_number() over (partition by to_date(transaction_date) order by (select null)) as rn from transaction44 --order by transaction_date ) ,cte2 as ( select transaction_date, transaction_id, last_value(run_sum) over (partition by transaction_date order by rn) amt, run_sum From cte ) select transaction_date, transaction_id,amt from cte2 where amt=run_sum;

  • @avi8016
    @avi8016 Жыл бұрын

    Great explanation sir 💯 Thanks a lot sir 🙏

  • @jojven7514
    @jojven7514 Жыл бұрын

    Awesome vdo ❤❤😇

  • @sugan1479
    @sugan1479 Жыл бұрын

    wow !!! Gifted to find like solution from you.we all learn together .waiting for many many more !!

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Glad to hear that

  • @kashmirshadows8150
    @kashmirshadows8150 Жыл бұрын

    Thank you !

  • @aaravkumarsingh4018
    @aaravkumarsingh4018 Жыл бұрын

    Sir please also add videos in database design playlist because that is also the most important part of interview along with sql

  • @ahmedtariqsilat
    @ahmedtariqsilat Жыл бұрын

    Ankit bhai superb explanation. I am waiting for your python playlist. Kindly post videos regarding that playlist as well

  • @tessysunny9600
    @tessysunny9600 Жыл бұрын

    Very good

  • @vikasgadhe7620
    @vikasgadhe7620 Жыл бұрын

    you are doing a noble work

  • @rohansrivastwa827

    @rohansrivastwa827

    Жыл бұрын

    Dealing doge ya khud bi solve karoge

  • @BismarckWangkhem
    @BismarckWangkhem Жыл бұрын

    Thank you Ankit for sharing :) Here is my approach: with raw_data AS (select transaction_date::date as transaction_date ,date_part('month', transaction_date) as month ,date_part('day', transaction_date) as day ,CASE WHEN type = 'withdrawal' THEN -amount else amount end u_amt from transactions) ,running_sum AS (select * ,SUM(u_amt) OVER(PARTITION BY month ORDER BY transaction_date ) as balance FROM raw_data) select DISTINCT transaction_date, balance from running_sum ORDER BY transaction_date

  • @sravankumar1767
    @sravankumar1767 Жыл бұрын

    Superb explanation 👌 👏 👍

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Thank you 😊

  • @rajeshramisetti83
    @rajeshramisetti83 Жыл бұрын

    Nice explanation Ankit.

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Thank you 😊

  • @vandanaK-mh9zo
    @vandanaK-mh9zo6 ай бұрын

    Script: create or replace table transaction44( transaction_id int , type string, amount float, transaction_date datetime ); insert into transaction44 values (19153, 'deposit', 65.90, '2022-07-10 10:00:00'), (53151, 'deposit', 178.55, '2022-07-08 10:00:00'), (29776, 'withdrawal', 25.90, '2022-07-08 10:00:00'), (16461, 'withdrawal', 45.99, '2022-07-08 13:00:00'), (77134, 'deposit',32.60, '2022-07-10 10:00:00');

  • @hariniramya7718
    @hariniramya7718 Жыл бұрын

    Awesome 👍

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Thank you! Cheers!

  • @abhishekpathak9454
    @abhishekpathak9454 Жыл бұрын

    Hi Ankit, Thanks for making these amazing videos. Could you please share is there any course for entry level employee on ssms… It will be helpful for many… ❤

  • @paulhartman3957
    @paulhartman3957 Жыл бұрын

    Where can we find the sample data and solution

  • @prashantmhatre9225
    @prashantmhatre9225 Жыл бұрын

    Thanks a lot for video , here is my solution with cte1 as ( SELECT transaction_date ,case when type = 'withdrawal' then -1 * amount else amount end new_amount FROM transactions ) , cte2 as ( select transaction_date , sum(new_amount) new_amnt from cte1 group by transaction_date ) select transaction_date , sum(new_amnt ) over ( partition by date_part('month',transaction_date) order by transaction_date) from cte2 order by 1;

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Good. Partition by should have year also

  • @prashantmhatre9225

    @prashantmhatre9225

    Жыл бұрын

    @@ankitbansal6 thanks bhai. Below is my modified and it’s working fine now and also accepted on datalemur. with cte1 as ( SELECT date(transaction_date) transaction_date ,case when type = 'withdrawal' then -1 * amount else amount end new_amount FROM transactions ) , cte2 as ( select transaction_date , sum(new_amount) new_amnt from cte1 group by transaction_date ) select transaction_date transaction_day , sum(new_amnt ) over ( partition by date_part('month',transaction_date) order by transaction_date) balance from cte2 order by 1;

  • @sahilummat8555
    @sahilummat8555Ай бұрын

    Hello Sir with cte as ( select transaction_id,type,amount, date_trunc('day',transaction_date) as transaction_date from transactions ) select distinct transaction_date, SUM(case when type='deposit' then amount else -1 * amount end ) over(partition by EXTRACT(month from transaction_date) order by transaction_date) as balance from cte

  • @TheVaibhavdang
    @TheVaibhavdang Жыл бұрын

    Is DATEPART not available on this platform?

  • @ARPITTHEIRONMAN
    @ARPITTHEIRONMAN Жыл бұрын

    Sahi hai but how about doing it without windows function

  • @HarishKumar-sh3bn
    @HarishKumar-sh3bn Жыл бұрын

    Hey Ankit, Can you dona sql project, a realtime one? To understand how it works.

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Sure

  • @niharvaishnav7628
    @niharvaishnav7628 Жыл бұрын

    Hi Ankit, your channel is one the best channel for SQL. Big thank you for providing this questions and their explanations. I have one technical (may be little non technical) question to ask: I have started practicing SQL on datalemur, most of the time i got correct answer using the concept of with CTE, however many times when i check website provided solution its rather not that much complex or would i say lengthy compare to what i used to get answer? Do you think it requires area of improvement or should i continue with this approach as i am comfortable with it and also getting correct answer.?? Thanks again

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    It's a good idea to try solving a problem with multiple approaches. It will give you more confidence. Moreover during interviews you should have more than 1 solution in your mind.

  • @niharvaishnav7628

    @niharvaishnav7628

    Жыл бұрын

    @@ankitbansal6 thank you very much 🙂🙂

  • @fakhrabashir6471
    @fakhrabashir6471 Жыл бұрын

    Thank you so much for these helpful videos .. Kindly upload SQL project videos and please make a video how we can update our resume with SQL related Projects ...?

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Sure

  • @fakhrabashir6471

    @fakhrabashir6471

    Жыл бұрын

    @@ankitbansal6 Respect from Pakistan

  • @ranadeepghosh1891
    @ranadeepghosh1891 Жыл бұрын

    Can u pls provide the code for ssms

  • @shivarajhalageri2513
    @shivarajhalageri2513 Жыл бұрын

    Great 🪄🙌

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Thank you 😊

  • @vishalbothra3643
    @vishalbothra3643 Жыл бұрын

    SELECT DISTINCT date(transaction_date), sum(case when type='deposit' then amount else -1*amount end) over (partition by extract(month from transaction_date) order by date(transaction_date) ) FROM transactions;

  • @prabhatgupta6415
    @prabhatgupta6415 Жыл бұрын

    hi ankit sir which recorder are you using?

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Chrome addon

  • @rahulmehla2014
    @rahulmehla2014Ай бұрын

    my soln: WITH cte AS( SELECT transaction_id, type, transaction_Date, CASE WHEN type = 'withdrawal' then -amount ELSE amount END as amount from transactions), cte2 AS( SELECT transaction_Date, SUM(amount) as balance FROM cte GROUP BY transaction_Date ORDER BY transaction_Date) SELECT transaction_Date, SUM(balance) OVER(PARTITION BY EXTRACT(year FROM transaction_date),EXTRACT(month FROM transaction_Date) ORDER BY transaction_date) as balance FROM cte2;

  • @NehaGupta-lf1sr
    @NehaGupta-lf1sr Жыл бұрын

    I am not able to see the problem using the URL provided in the desc section

  • @BI-Rahul

    @BI-Rahul

    8 ай бұрын

    This question is no longer under free category. It requires a premium subs

  • @adityabaha
    @adityabaha Жыл бұрын

    Hi Ankit, Thanks for all your videos. I've gained a lot of confidence watching & practicing them(And also landed my dream job🙏). I had a doubt if you could help explain, May be with an example, It would be great. I want to understand what is the difference between below two, if there is any at all? CASE WHEN DIMENSION_FIELD IN ('X', 'Y') THEN SUM(MEASURE_FIELD) END AS AGGREGATION_1, SUM(CASE WHEN DIMENSION_FIELD IN ('X', 'Y') THEN MEASURE_FIELD END) AS AGGREGATION_2 Really appreciate your help, support & guidance. Thanks in advance 😊🙏

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Sure will do

  • @adityabaha

    @adityabaha

    Жыл бұрын

    @@ankitbansal6 Thank You 😊

  • @rashmidutta7151
    @rashmidutta7151 Жыл бұрын

    with c2 as ( with c as ( SELECT type,amount,transaction_date::DATE as dt from transactions) SELECT dt, sum(case when type='withdrawal' then -1*amount else amount end) as daily FROM c group by dt ) select dt,sum(daily) over(partition by EXTRACT (MONTH FROM dt) order by dt) from c2

  • @aapbeete9761
    @aapbeete97619 ай бұрын

    WITH cte AS ( SELECT transaction_date, SUM(CASE WHEN type = 'deposit' THEN amount ELSE -amount END) AS daily_balance FROM transactions GROUP BY transaction_date ) SELECT transaction_date, SUM(daily_balance) OVER (PARTITION BY YEAR(transaction_date), MONTH(transaction_date) ORDER BY transaction_date) AS balance FROM cte ORDER BY transaction_date;

  • @arpanscreations6954
    @arpanscreations695427 күн бұрын

    As of today, it is no longer free. It requires subscription :(

  • @shivkumarpatel7940
    @shivkumarpatel7940 Жыл бұрын

    Review it WITH Balance_left as ( select DATE( transaction_date ) as transaction_date, SUM( CASE WHEN type= 'deposit' THEN amount WHEN type= 'withdrawal' THEN -amount ELSE 0 END) as balance from transactions group by DATE( transaction_date ) ORDER BY DATE( transaction_date ) ASC ) select transaction_date, SUM( balance ) OVER( PARTITION BY date_part('month', transaction_date ) ORDER BY DATE( transaction_date ) ) as balance FROM Balance_left Love you Sir thanks for your support

  • @ankitbansal6

    @ankitbansal6

    Жыл бұрын

    Good

  • @ethyria7685
    @ethyria7685Ай бұрын

    SELECT cast(transaction_date as date) as date, sum(CASE WHEN type = 'withdrawal' THEN -1*amount ELSE amount END)OVER(PARTITION BY datepart(MONTH, cast(transaction_date as date)), datepart(year, cast(transaction_date as date)) ORDER BY transaction_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as amountnew from trans2

  • @vinothvk2711
    @vinothvk27118 ай бұрын

    Dummy Script: create table transact(transaction_id integer, type varchar(20), amount float(10), transaction_date date ) insert into transact(transaction_id,type,amount, transaction_date) values(19153, 'deposit', 65.90, '2022-10-07') insert into transact(transaction_id,type,amount, transaction_date) values(53151, 'deposit', 178.55, '2022-08-07') insert into transact(transaction_id,type,amount, transaction_date) values(29776, 'withdrawal', 25.90, '2022-08-07') insert into transact(transaction_id,type,amount, transaction_date) values(16461, 'withdrawal', 45.99, '2022-08-07') insert into transact(transaction_id,type,amount, transaction_date) values(77134, 'deposit', 32.66,'2022-10-07') insert into transact(transaction_id,type,amount, transaction_date) values(29776, 'deposit', '500', '2022-08-08')

  • @ithamarhardy3055
    @ithamarhardy3055 Жыл бұрын

    to solve this probleme you need susbcribe to premium , how can i do it without subscribe thanks Ankit

Келесі