Solving a Real SQL Interview Problem | Job Vacancies SQL Query

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ย. 2024

ความคิดเห็น • 151

  • @raghulmohan5937
    @raghulmohan5937 ปีที่แล้ว +9

    You are master in sql we need more problems like this

  • @vikrantheswar7685
    @vikrantheswar7685 ปีที่แล้ว +14

    I really like your explanation. I can see your teaching passion in it. Continue sharing knowledge 👍🙌👏

    • @techTFQ
      @techTFQ  ปีที่แล้ว +1

      Thanks a lot :)

  • @Mayank-jw9yy
    @Mayank-jw9yy หลายเดือนก่อน

    this video is absolute gem to watch, no better person available on internet to teach you SQL.

  • @babahussain786
    @babahussain786 ปีที่แล้ว +4

    First of all thanks for uploading this type of SQL video and Please upload more videos like this and if you have time please make live videos as well

    • @techTFQ
      @techTFQ  ปีที่แล้ว +2

      Live streaming to solve problems.. good suggestion, will consider it

  • @yugendarsairam9688
    @yugendarsairam9688 ปีที่แล้ว +3

    Hey Toufik, your lectures are super helpful in understanding the concepts in a much better way. Appreciate your inputs here. Could you please make a video on transactions and indexes, that would really help a lot to all our folks.

  • @kaivalyapatkar9288
    @kaivalyapatkar9288 ปีที่แล้ว +1

    I request you to please start a Interview Problems Series! It would help a lot!

  • @decimus1447
    @decimus1447 7 หลายเดือนก่อน

    I did it using the recursive method. Don't worry about column names in recursion. I just needed to understand recursion.
    with t1 as
    (select name, position_id,
    ROW_NUMBER() over(partition by position_id order by id) as rn
    from job_employees
    )
    ,job_cte as
    (select id as dd, 1 as cnt, title, groups, levels, payscale
    from job_positions
    union all
    select b.id, cnt+1, b.title, b.groups, b.levels, b.payscale
    from job_positions b
    inner join job_cte a on a.dd = b.id and cnt

  • @ejjirotusrinivas8376
    @ejjirotusrinivas8376 ปีที่แล้ว +4

    with cte(lvl,id,title,groups,levels, payscale,totalpost) as (select 1 as lvl,id,title,groups,levels, payscale,totalpost
    from job_positions union all select lvl+1 as lvl,id,title,groups,levels, payscale,totalpost
    from cte where lvl

  • @shrinath29
    @shrinath29 ปีที่แล้ว +16

    Please upload more videos like this 👌👌

    • @ryuhayabusa3540
      @ryuhayabusa3540 ปีที่แล้ว +3

      I love theses videos

    • @techTFQ
      @techTFQ  ปีที่แล้ว +2

      Thank you guys 😍

    • @armaanp5585
      @armaanp5585 11 หลายเดือนก่อน

      Indeed these are good videos. I found the below interesting SQL interview task for Data Analyst. This may help.
      th-cam.com/video/g-bLekv2kjU/w-d-xo.html

  • @dantushankar4470
    @dantushankar4470 2 หลายเดือนก่อน

    My solution which is little similar:
    with cte as (select a.title as t ,a.groups as g ,a.levels as l ,a.payscale as p , b.name as n from (select jp.*, row_number() over (partition by id order by id) as r1 from job_positions jp, generate_series(1,jp.totalpost)) a left join
    (select *, row_number() over (partition by position_id order by id) as r2 from job_employees) b on a.r1 = b.r2 and a.id = b.position_id)
    select t, g, l, p, case when n is null then 'Vacant' else n end as Emp_Name from cte;

  • @archisingh9892
    @archisingh9892 9 หลายเดือนก่อน +4

    Sir.... Why I am not getting idea to write query like you did in this video.... I know each functions but still I am. Not able to write complex query. Please give me some idea how can I improve atleast 40% of your SQL knowledge.

    • @techTFQ
      @techTFQ  8 หลายเดือนก่อน

      Practice. All the best

  • @Manzur.A
    @Manzur.A ปีที่แล้ว

    This TH-camr is the best and will go far more than other TH-camrs.

  • @Tusharchitrakar
    @Tusharchitrakar ปีที่แล้ว +1

    I used recursive cte to stack up the job postings (similar to ungrouping) but thanks for this alternate solution

  • @nachiketpalsodkar4356
    @nachiketpalsodkar4356 ปีที่แล้ว +8

    Another Simpler WAY!!!!
    ;
    WITH cte as (
    SELECT e.id,title,groups,levels,payscale,name,totalpost
    , ROW_NUMBER() OVER(PARTITION BY p.groups ORDER BY p.groups) as RNK
    FROM job_employees as e CROSS JOIN job_positions as p )
    ,cte1 as (
    SELECT *
    FROM cte
    WHERE RNK

    • @techTFQ
      @techTFQ  ปีที่แล้ว +2

      Nice .. thanks for sharing

    • @nachiketpalsodkar4356
      @nachiketpalsodkar4356 ปีที่แล้ว

      @@techTFQ Most welcome

    • @florincopaci6821
      @florincopaci6821 ปีที่แล้ว

      Your solution return incorect results.

    • @nachiketpalsodkar4356
      @nachiketpalsodkar4356 ปีที่แล้ว

      @@florincopaci6821 Kindly check the table names that you are using also i have used SQL server for the solution

    • @florincopaci6821
      @florincopaci6821 ปีที่แล้ว +1

      @@nachiketpalsodkar4356 You are right. Your solution gave correct Output in Sql Server and Postgresql but in Oracle-NO.
      Thank you

  • @viktorponomarev4048
    @viktorponomarev4048 ปีที่แล้ว

    The same solution pop-uped in my head. Definitely there are other ways to solve the problem, but the shown solution is clever and readable and I cant figure out the better one.

  • @user-dv7pt6no6c
    @user-dv7pt6no6c ปีที่แล้ว +2

    Mine solution was same as yours. Except I use recursive CTE to generate series in MS SQL. 😀

    • @anjankumaro7530
      @anjankumaro7530 11 หลายเดือนก่อน

      Can you share me the code of CTE. your used.

    • @sammail96
      @sammail96 6 หลายเดือนก่อน

      @@anjankumaro7530I don't know exactly his solution but let try this oracle sql query: WITH CTE AS (
      SELECT E.*, ROW_NUMBER() OVER (PARTITION BY GROUPS ORDER BY GROUPS) AS RN FROM (
      SELECT * FROM JOB_EMPLOYEES J
      JOIN JOB_POSITIONS JP
      ON J.POSITION_ID = JP.ID) E),
      CTE1 AS (
      SELECT F.*, ROW_NUMBER() OVER (PARTITION BY GROUPS ORDER BY GROUPS) AS RN FROM (
      SELECT
      ID,
      TITLE,
      GROUPS,
      LEVELS,
      PAYSCALE
      FROM job_positions
      CONNECT BY PRIOR ID = ID
      AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL --if not used then error: CONNECT BY LOOP in user data
      AND LEVEL

  • @integer4531
    @integer4531 ปีที่แล้ว +3

    My version, But a bit unreadable(
    with cte as (select level rownb from dual connect by level

    • @techTFQ
      @techTFQ  ปีที่แล้ว +2

      nice man, well done

  • @martinberger365
    @martinberger365 5 หลายเดือนก่อน

    You rock, bro! Haven't seen someone that keen on SQL than you!

  • @venkateswararaodevisetti8684
    @venkateswararaodevisetti8684 ปีที่แล้ว +2

    Hi Sir,
    I have answered by pausing your video
    Below is my query, not sure whether u used same way or not
    with recursive job_positions_data as
    (
    select id,title,grp,levels,payscale,1 as row_id,totalpost from job_positions
    union
    select id,title, grp,levels,payscale,row_id + 1 as row_id,totalpost from job_positions_data
    where row_id

  • @dilipinamdar5523
    @dilipinamdar5523 ปีที่แล้ว +1

    Thanks for uploading this type of SQL video..I am unable to use generate_series function in mysql ..please suggest!!!!

  • @swapnildhivar930
    @swapnildhivar930 ปีที่แล้ว +1

    I solved using Cte ' s only and another solution is using recursive cte ( i used MySQL)

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      Awesome 👌 well done

  • @csekhar4155
    @csekhar4155 ปีที่แล้ว +3

    Your teaching is awesome. When are you starting sql boot camp for new batch?

    • @techTFQ
      @techTFQ  ปีที่แล้ว +1

      I will release a recorded course next month

    • @richardtorrenueva5512
      @richardtorrenueva5512 ปีที่แล้ว

      Bootcamp like this will join

    • @RaviYadav-cx2pb
      @RaviYadav-cx2pb ปีที่แล้ว

      ​@@techTFQ really needed SQL bootcamp on graphy

  • @felipemv13
    @felipemv13 ปีที่แล้ว +1

    Parabéns pelo ótimo vídeo - ótima explicação e detalhamento de cada passo. Muito bom!!!
    Congratulations for the great video - great explanation and detailed step by step. Very good!!!

  • @satyaprakashdash459
    @satyaprakashdash459 2 หลายเดือนก่อน

    with recursive cte as (
    select id,title,groups,levels,payscale,totalpost from job_positions
    union
    select id,title,groups,levels,payscale,totalpost-1 as totalpost from cte where totalpost >1
    ),cte2 as (select id,name,position_id, row_number() over(partition by position_id) as rn from job_employees)
    , cte3 as(
    select a.*,b.* from cte a
    left join cte2 b on a.id=b.position_id and a.totalpost=b.rn)
    select title, groups,levels,payscale,case when name is not null then name else 'Vacant' end as employeename from cte3

  • @abhijathprasanth8542
    @abhijathprasanth8542 11 หลายเดือนก่อน +1

    Hi, can you upload the same in oracle db?

  • @avinashpratapsingh3875
    @avinashpratapsingh3875 ปีที่แล้ว +1

    Hi Thoufiq thanks for this question, please make video for query asked in MAANG companies.

  • @priyankasuryavanshi6888
    @priyankasuryavanshi6888 10 หลายเดือนก่อน

    Your explanation is on another level, Thanks!!! It's really helpful

    • @techTFQ
      @techTFQ  8 หลายเดือนก่อน +1

      You're very welcome!

  • @meenarnath9091
    @meenarnath9091 5 หลายเดือนก่อน

    This is really a service. Thank you so much Sir.

  • @user-pm2sz7lc6q
    @user-pm2sz7lc6q 6 หลายเดือนก่อน

    This dude is a genius 🎉

  • @aadamhaydin5895
    @aadamhaydin5895 ปีที่แล้ว

    Really loved the way you simplied the problem.

  • @ibrahimidris7741
    @ibrahimidris7741 ปีที่แล้ว +1

    Select Emp_name, title, Group, Level, payscal
    From Emp
    Where Position_ID = ID,

  • @nieja5920
    @nieja5920 ปีที่แล้ว

    Thanks!! learnt something new today, can you upload a version of this using recursive sql? Thanks!

  • @manickavasuki2375
    @manickavasuki2375 ปีที่แล้ว +4

    Hi Thoufiq I want to learn sql from basic to advance when are you launching ur course in Udemy

    • @YasinKAYA-do4ek
      @YasinKAYA-do4ek ปีที่แล้ว +1

      m2

    • @techTFQ
      @techTFQ  ปีที่แล้ว +3

      I will launch the course soon and it will be on my own platform .. working on it currently

    • @YasinKAYA-do4ek
      @YasinKAYA-do4ek ปีที่แล้ว

      @@techTFQ so no udemy then. Will there be certificate? I wanna show of that I learned SQL in my cv. Otherwise people don't take it seriously when I say I have been managing ERP database for years. Apperantly some paper makes more impact than years of developing ERP software on my own.

  • @sanmeetsingh8255
    @sanmeetsingh8255 ปีที่แล้ว

    Great explanation so I also want to send you an interview question related to SQL. Can you please tell me where can I send that question?

  • @MdNisarAhmed-de7vd
    @MdNisarAhmed-de7vd ปีที่แล้ว

    Your content is so good that i like your video before even watching ❤️

  • @edwardmensah4110
    @edwardmensah4110 ปีที่แล้ว +1

    Thanks.
    Please make more of this video

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      Thank you will do

  • @monicabn3067
    @monicabn3067 ปีที่แล้ว

    Best one sir❤ please keep educating and challenging us🎉

  • @bijumohan9460
    @bijumohan9460 ปีที่แล้ว

    Hi Taufiq can you pls do a video on using connect by clause in oracle?

  • @sammail96
    @sammail96 6 หลายเดือนก่อน

    This is very interesting problem

  • @nandinimnair9915
    @nandinimnair9915 ปีที่แล้ว

    Hi, Thankyou for yet another wonderful video.can you please let me know which oracle certification a person with 12 yrs of experience in plsql should take..?

  • @beks5755
    @beks5755 ปีที่แล้ว

    @techTFQ I assume this task is not from a junior position interview but more like mid or senior-level? Am I right?

  • @kashmirshadows8150
    @kashmirshadows8150 ปีที่แล้ว

    Thanks you Thoufiq
    Any update on the Udemy course ??

  • @chibumbamohammed5006
    @chibumbamohammed5006 ปีที่แล้ว +1

    I have liked this video it so challenging.

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      thank you

  • @santhoshKumar-zf7ox
    @santhoshKumar-zf7ox ปีที่แล้ว

    Hi, I have a question on dates, I need to get date of 2 or 3rd occurence of Monday in a month, please make a video or SQL query..

  • @nivisworld1513
    @nivisworld1513 ปีที่แล้ว

    Sir, please post all the sql classes please sir..........i am trying for job but so many qns on sql they are asking.....iam very poor in sql....but while listening your classes i clearly understand the concept ......plz....if i want talk about course personally ...how cam i contact you sir.....plz rply me sir....

  • @murapalasravani2519
    @murapalasravani2519 11 หลายเดือนก่อน

    SIR, we can also join job_positions and employee by only using position_id as common column right? then what is the need of using row number window function there?

  • @shiju94
    @shiju94 ปีที่แล้ว

    Wonderful explanation sir.

  • @siddharthshivdasani
    @siddharthshivdasani ปีที่แล้ว

    Hey! What if we took row number instead of generate series for job_positions table n gonna partition by title which had the value of manager n all…. It would also give same output na??

  • @gobindaroy7811
    @gobindaroy7811 ปีที่แล้ว +1

    Please upload more such videos

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      noted will do

  • @rajasekhar8261
    @rajasekhar8261 ปีที่แล้ว

    Any update on your oracle course learning videos. You mentioned that you are going to create a platform and place your videos there?

  • @charlesarome5792
    @charlesarome5792 ปีที่แล้ว

    Good content, u are too fast in ur delivery, please ,if u can speak slowly so we can grasp

  • @user-rr1mf4tm7z
    @user-rr1mf4tm7z ปีที่แล้ว +2

    Sir I have a task releted to banking sector for Sql how can I send you question

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      email me

  • @huzaifahshah3841
    @huzaifahshah3841 ปีที่แล้ว

    Yes sir make more Videos solved the problems

  • @allrounderashok4712
    @allrounderashok4712 2 หลายเดือนก่อน

    SQL SERVER SOLUSTION
    with cte as
    (
    select 1 n, id,title,groups, level, payscale,totalpost from postition
    union all
    select n+1,id,title,groups,level,payscale,totalpost from cte
    where n

  • @sajidulahmed7972
    @sajidulahmed7972 11 หลายเดือนก่อน

    Thanks for the problem! May I know, if this is the question for an experienced person who’s looking for a Data role or even for freshers, we gonna get such questions? And if it’s for an experienced guy, then may I know the count of exp? If any one can help me as I am trying to change my domain into Data roles.

  • @Manojkumar__
    @Manojkumar__ ปีที่แล้ว +1

    where can I learn these kind of new functions like Generate_series?

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      google bro, i am not aware of any cheat sheet with this info

  • @kk-rk9xg
    @kk-rk9xg ปีที่แล้ว +3

    Will you be launching an SQL bootcamp later this year?

    • @techTFQ
      @techTFQ  ปีที่แล้ว +1

      Yes I’ll launch a recorded sql course next month

    • @mdammar
      @mdammar ปีที่แล้ว

      Keep price less 😅

  • @shaikhanuman8012
    @shaikhanuman8012 ปีที่แล้ว

    Clear cut explanation tq sir

  • @user-mm6sp1tc4p
    @user-mm6sp1tc4p 11 หลายเดือนก่อน

    hello, would you please solve some interviews like these are but for python?

  • @TheDataMagic_x
    @TheDataMagic_x 8 หลายเดือนก่อน

    You have other options to solve because sir my system does not accept the generate_ series' function

  • @kirankumarbm7391
    @kirankumarbm7391 ปีที่แล้ว +1

    Superb, Thanks

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      Your welcome 🙏

  • @olaidealafia1965
    @olaidealafia1965 10 หลายเดือนก่อน

    Very helpful and detailed

    • @techTFQ
      @techTFQ  8 หลายเดือนก่อน

      Glad you liked it

  • @shivinmehta7368
    @shivinmehta7368 8 หลายเดือนก่อน

    my solution
    with recursive cte as
    (
    select id,title,groups,levels,payscale,totalpost,1 as n
    from job_positions
    union
    select id,title,groups,levels,payscale,totalpost,n+1 as n
    from cte where totalpost>n
    )
    select cte.title,cte.groups,cte.levels,cte.payscale,cte.totalpost,coalesce(e.name,'vacant')
    from cte
    left join
    (select *,row_number() over(partition by position_id order by id) as rn from job_employees) e
    on cte.id=e.position_id and cte.n=e.rn
    order by cte.id

  • @abdullahsheikh5459
    @abdullahsheikh5459 5 หลายเดือนก่อน

    How do I solve this query in mysql DB as generate_series() is not present in mysql ??

  • @jithin_raj
    @jithin_raj 5 หลายเดือนก่อน

    with recursive cte_rec as
    (select id,title,groups,levels,payscale,totalpost, 1 as level
    from job_positions
    union
    select id,title,groups,levels,payscale,totalpost,level+1
    from cte_rec
    where level

  • @sreenivasulukanchi1612
    @sreenivasulukanchi1612 8 หลายเดือนก่อน

    In MS SQL Server, there is no Generate_Series.

  • @mikarshdataanalyst4086
    @mikarshdataanalyst4086 ปีที่แล้ว

    Great video Thoufiq!

  • @joerokcz
    @joerokcz ปีที่แล้ว +1

    Please upload more

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      noted will do

  • @RaviYadav-cx2pb
    @RaviYadav-cx2pb ปีที่แล้ว

    Can you please launch new course beginners to pro sql with project on graphy

  • @Jami_Sarat_Kumar580
    @Jami_Sarat_Kumar580 ปีที่แล้ว

    Good explanation ,
    But generate_series not available in sql server management studio 2022. And i have one doubt ISNULL replacing null values and COALESCE its returns 1st non null value of in our table data am i right?
    Then what is difference main between ISNULL and coalesc?
    Can you please tell me tfq

    • @ManpreetSingh-tv3rw
      @ManpreetSingh-tv3rw 11 หลายเดือนก่อน

      you can use recursive cte to do the same thing, I have mentioned in comments my solution for sql server

  • @mmanoj3287
    @mmanoj3287 ปีที่แล้ว

    I have one interview Question I can’t answer, can you help me
    Q : one table have 30 Indexes how to find good and bad one In SqlServer

  • @vijayroyal12
    @vijayroyal12 11 หลายเดือนก่อน

    Please upload more scenarios anna

  • @newenglandnomad9405
    @newenglandnomad9405 ปีที่แล้ว +1

    Would this qualify as intermediate or advanced? I can't get generate series to work on mysql 8 workbench.

    • @techTFQ
      @techTFQ  ปีที่แล้ว +2

      I would say intermediate .. in MySQL you can solve it using recursive sql .. I’ve shared the solution in my blog

  • @paularakowska6060
    @paularakowska6060 ปีที่แล้ว

    Amazing, thanks!;)

  • @lovebites4098
    @lovebites4098 10 หลายเดือนก่อน

    can u please find how to do the same in mysql

  • @funshojegsin5431
    @funshojegsin5431 7 หลายเดือนก่อน

    pls which sql database are you using
    because I'm using azure?

  • @life69kk
    @life69kk ปีที่แล้ว +1

    Please make plsql course?

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      I’m planning for next year

  • @viveks4935
    @viveks4935 11 หลายเดือนก่อน

    How to solve it in mysql and oracle db?

  • @ajkuchipudi893
    @ajkuchipudi893 ปีที่แล้ว

    pls upload more like this

  • @Canadavlogsbyanu
    @Canadavlogsbyanu ปีที่แล้ว

    I really loved your videos❤

  • @devarakondasankararao3802
    @devarakondasankararao3802 11 หลายเดือนก่อน

    Great video

  • @haneefurs
    @haneefurs 11 หลายเดือนก่อน

    Thanks a lot

  • @powerstock9464
    @powerstock9464 11 หลายเดือนก่อน

    Not sure If I am new to SQL or this was very confusing for me :(

  • @Krishna48784
    @Krishna48784 ปีที่แล้ว

    I have one small question, in postgresql how can we return multiple results sets with different column size , Ms SQL server returned this , but in postgresql is it possible. Give answer please

  • @durganjaneyulukatiki1781
    @durganjaneyulukatiki1781 ปีที่แล้ว +1

    Hi Thofic i want sql course recording classes

    • @techTFQ
      @techTFQ  ปีที่แล้ว +1

      recorded sql course should release next month

  • @in-and-around3681
    @in-and-around3681 ปีที่แล้ว

    Hi sir i have I sql interview query please help me.
    Write a query to get all months end date of any year or given year.

  • @Ibad_gamer937
    @Ibad_gamer937 ปีที่แล้ว

    Amazing

  • @rishabhgupta3826
    @rishabhgupta3826 11 หลายเดือนก่อน

    Hi Sir, Require one help related to mysql query where a table having data into month and yearwise only with single or multiple value so want to extract data where if same month and year repeated twice with different value then column M1 return M1='R' and again M1='B' and if same month and year repeated only once say Aug2023 then M2='R' and again M2=' ' and if again another same month and year repeated only once I.e sept2023 then M3='B' and M3=' ' respectively into mysql, kindly help me to share the way or query through which I can make on my db and can extract the data

  • @luckyyyyy790
    @luckyyyyy790 ปีที่แล้ว +1

    bro make a video on keys in sql

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      you mean constraints?

    • @luckyyyyy790
      @luckyyyyy790 ปีที่แล้ว +1

      yes sir
      @@techTFQ

    • @luckyyyyy790
      @luckyyyyy790 ปีที่แล้ว +1

      when can i expect a video sir

    • @techTFQ
      @techTFQ  ปีที่แล้ว

      Not really planning on it .. I teach it during my sql course

    • @luckyyyyy790
      @luckyyyyy790 ปีที่แล้ว

      Where can I get your SQL course

  • @ganeshv791
    @ganeshv791 ปีที่แล้ว

    Vera level

  • @samratsingha8515
    @samratsingha8515 ปีที่แล้ว

    Super

  • @manoj_m0393
    @manoj_m0393 11 หลายเดือนก่อน

    This seems so overwhelming

  • @fathimafarahna2633
    @fathimafarahna2633 ปีที่แล้ว +1

    👌👌👌👌

  • @Alexpudow
    @Alexpudow 7 หลายเดือนก่อน

    with a as (
    select position_id, char(null) name, cnts, totalpost
    from
    (select distinct position_id, totalpost, totalpost - count(a.id) over(partition by position_id) cnts,
    count(a.id) over(partition by position_id) cnt
    from
    job_employees a join
    job_positions b on a.position_id = b.id) t
    where cnt

  • @codingoak4701
    @codingoak4701 ปีที่แล้ว

    I have a solution to this posted on my channel.

  • @Kiranmai30
    @Kiranmai30 ปีที่แล้ว

    Thanks a lot