Analytical Functions in oracle explained with real examples

Поделиться
HTML-код
  • Опубликовано: 6 сен 2024
  • This video explains analytical functions and how they are implemented in real projects.
    Analytical functions are somewhat similar to aggregate functions,but they offer much more.
    Why use analytical function ? They allow you to write fast and concise queries which otherwise will involve self join and long processing times
    They allow you to perform aggregate functions independently on sets of partitions. You can access values from previous rows in current row and you can restrict the window on which you want to apply this analytical function.
    I have given additional practice exercises along with the dataset so that you can comfortably work with analytical functions.
    You can find the sample problems along with dataset in the below link.
    www.internships...
    #AnalyticalFunctions #OracleAnalyticalFunctions #TechCoach

Комментарии • 223

  • @nileshk1455
    @nileshk1455 5 лет назад +6

    I think these are one of the best videos available on RUclips. Appreciate your efforts in making these videos.. And many many thanks

    • @TechCoach
      @TechCoach  5 лет назад

      Thanks a lot for the kind words. I have a small request, I am working on this new channel and will really appreciate if you watch and subscribe to it.
      ruclips.net/video/IP2Vn6jK8Hg/видео.html

  • @tushargursale6060
    @tushargursale6060 5 лет назад +4

    Hello
    In your video ...at the point where you are explaining cumulative sum, you said order by doesn't matter but in fact it matters a lot if you don't specify order by clause it will not provide the cumulative sum of salaries instead it will give sum of salaries department wise.
    Other than that it was a very helpful video thanks a lot man...keep up good work...

    • @modakad
      @modakad 4 года назад

      Thanks for this comment. I too thought the same

    • @TechCoach
      @TechCoach  2 года назад

      I made a mistake If I said that. My apologies.
      Order does matter

  • @sheebaashraf
    @sheebaashraf 4 года назад +3

    Excellent !!!. Thank you very much for deep explanation.
    Solution of exercises 1:
    select min(salary) over (partition by job_id) as min_sal
    ,a.* from emp a;
    2:
    select e.* ,(salary+salary*.10) as Bonus
    from (
    select lag(hire_date,1,null) over (partition by department_id order by hire_date ) as old_emp, a.* from emp a) e where e.old_emp is null;
    3:select count(*) over (partition by manager_id ) as cntofReportee,a.* from emp_bk a
    4:select a.*, avg(salary) over (partition by department_id) from emp a where
    (months_between(sysdate ,hire_date) /12)> =12;
    I am confused about order by ,when to use and when not .Please clear my doubt.

    • @TechCoach
      @TechCoach  4 года назад +1

      I will review them real quick and will let you know :), for order by try practicing an example using lag and lead function it shall clear all your doubts :)

  • @devinderbombrah2394
    @devinderbombrah2394 3 года назад +2

    The narrative is very well-paced, a very good presentation. Good to see such videos and hope we shall have more from you.

    • @TechCoach
      @TechCoach  3 года назад +1

      Thanks Devinder for the kind words :)

  • @sahilpundora8800
    @sahilpundora8800 6 лет назад +1

    Thank you for the video. Really helpful to understand OLAP basics.
    On a light note, when you said at 18:35 "to come up with an easier answer to find the money spent by company as salary to employees", well, instead of cumulative, we can just use SELECT SUM(SALARY) FROM EMPLOYEE; and if we want department wise, we can use the same with GROUP BY clause. I believe there is a fine line where we should use all these OLAP functions or aggregate functions.

    • @TechCoach
      @TechCoach  6 лет назад

      Thanks for the kind words, I will review what I have mentioned at 18:35 :)

    • @TechCoach
      @TechCoach  6 лет назад

      I would love your support for my new channel, Please watch subscribe and share with your friends.
      ruclips.net/channel/UCoLdaMxhfDgdgIAcRGlUvkg

  • @akshaykadbane9482
    @akshaykadbane9482 2 года назад +1

    select*from (
    select lag(hire_date) over(partition by department_id order by hire_date) as old_emp,a.*, (salary+(0.1*salary)) as new_salary from employees a order by employee_id) where old_emp is null order by employee_id

  • @aleksandraarsic1100
    @aleksandraarsic1100 5 месяцев назад +1

    A legend himself 🙏🏻 Big thanks!

    • @TechCoach
      @TechCoach  5 месяцев назад +1

      I am glad I could help :)

  • @nishikantadik5817
    @nishikantadik5817 2 года назад +1

    You are doing great . You are actually help me to understand it in easier way . 😃 Thank you so much brother.

    • @TechCoach
      @TechCoach  2 года назад

      Thanks buddy,
      Try these 3 videos as well on the same topic, they will help you a lot :)
      ruclips.net/video/7sJ3FooAuBE/видео.html

  • @mithaSantara
    @mithaSantara 3 года назад +3

    Correction -- @12:05 you said Previous value -- so in LEAD() it should be Next row not previous value. if its a LAG() I can understand. Hope this is useful to the viewers.

    • @karel8y
      @karel8y 2 месяца назад

      I second this; it should be next row.

  • @madhavikatta7346
    @madhavikatta7346 2 года назад +1

    Vivek please continue your effort. Nice explanation.

    • @TechCoach
      @TechCoach  2 года назад

      Thanks a lot Madhavi :)

  • @patrickng6606
    @patrickng6606 3 года назад +2

    Wow didn’t know analytical function is so powerful until now

    • @TechCoach
      @TechCoach  3 года назад

      Thanks Patrick I am glad I could help

  • @ShaikAbdulArif
    @ShaikAbdulArif 5 лет назад +1

    thanks for making best video, I haven't seen before, great job and appreciate your efforts

    • @TechCoach
      @TechCoach  5 лет назад

      I am glad shaik abdul arif I could be of any help. I have a small request, I am working on this new channel please do watch share and subscribe to it.
      Your support is my motivation.
      ruclips.net/video/Oz4TbQwrrOY/видео.html

  • @rashisingh6985
    @rashisingh6985 4 года назад

    Best Explanation of Analytical functions. Thank you!

    • @TechCoach
      @TechCoach  4 года назад

      Thanks a lot Rashi for the kind words :)

  • @shivkanyashinde1607
    @shivkanyashinde1607 4 года назад +5

    Yes correct , but what if we have 2 employees in same department hired on same date ...for example in this scenario department 80 hired 2 employees on same day so it should show 2 employees with analytical function as recent joinee but it shows only one .

    • @TechCoach
      @TechCoach  4 года назад +2

      You are right Shivkanya, I mean a real project query will be a little more sophisticated covering such scenarios. But good catch :)

    • @vikastiwari8935
      @vikastiwari8935 4 года назад +2

      @@TechCoach so, what is the correct ans of Shivkanya's doubt ?

    • @gauravdutta5486
      @gauravdutta5486 3 года назад

      Hi Shivkanya ,
      in this scenario it is good to use the dense_rank function , below query can be used :-
      select * from (select e.* , dense_rank() over(partition by deptno order by hiredate desc) as recent_joinee from EMP e) where recent_joinee=1;
      even if 10 people joined on the same date , there rank will be same

    • @sravaniskitchen344
      @sravaniskitchen344 3 года назад

      @@TechCoach hi please answer shivakanyas doubt ..

  • @vishvadeepmohanpandey129
    @vishvadeepmohanpandey129 Год назад

    Very Good Explanation looking forward more videos like that. Given link is not working please provide link to download the data set

  • @ssthanu
    @ssthanu 6 лет назад +1

    Excellent. You made my life easy. Thanks

    • @TechCoach
      @TechCoach  6 лет назад

      Thanks for the kind words, I have a small request I am working on a new youtube channel " An Indian Abroad" .
      I would really appreciate if you watch and subscribe to it.
      ruclips.net/video/HBQHekM1U2c/видео.html

  • @maheshnaidu1784
    @maheshnaidu1784 4 года назад

    Excellent Vivek.. The best explanation over analytical functions..
    Thank a lot...

    • @TechCoach
      @TechCoach  4 года назад

      Thanks Mahesh for the kind words.
      I have a small request, I am working on this new channel please do watch and subscribe to it.
      Your support is my motivation. ruclips.net/video/JobONiVWA9Q/видео.html

  • @durweshsapkar9070
    @durweshsapkar9070 5 лет назад

    Excellent Sir i am working on production environment i had faced so many times this difficulties bu after watching this i definetely improved my knowledge.
    Thanks you so much please make more videos about debugging and give some shortcuts while using plsql developers

    • @TechCoach
      @TechCoach  5 лет назад

      Thanks durwesh for the kind words, I will certainly work on more videos.Meanwhile
      I have a small request, I am working on this new channel please do watch and subscribe to it.
      Your support is my motivation.
      ruclips.net/video/Oz4TbQwrrOY/видео.html

  • @ranajparida3902
    @ranajparida3902 4 года назад

    Find most recent employee
    Select * from emp where hiredate in ( select max(hiredate) from emp group by deptno); - this is done in Sub Query. No need to introduce Self join with join condition.

  • @rajkumarpanditYouTub
    @rajkumarpanditYouTub 5 лет назад

    Great Sir. Highly appreciated. The way you presented and talked highly impressive. #Respect.

    • @TechCoach
      @TechCoach  5 лет назад

      Thanks Raj for the kind words, It means a lot to me. I have a small request, I am working on this new channel and would really appreciate if you watch and subscribe to it.
      ruclips.net/video/IP2Vn6jK8Hg/видео.html

  • @shivkanyashinde1607
    @shivkanyashinde1607 4 года назад +1

    1 :
    select * from (
    select e.*,min(e.salary) over(partition by e.job_id) as min_salary from employees e order by e.job_id ) where salary = min_salary;
    2:
    select a.*,((a.salary * 10)/100) as bonus from (
    select e.*,lag(e.hire_date) over(partition by e.department_id order by e.hire_date) as oldest_emp from employees e) a
    where a.oldest_emp is null;

    • @rohithreddy6895
      @rohithreddy6895 4 года назад +1

      hi shivkanya you need to add order by hiredate desc to pick dept wise oldest_emp otherwise it would pick dept wise recent emp

  • @keshavjain8644
    @keshavjain8644 4 года назад

    --Q1
    select * from
    (
    select min(salary) over (partition by job_id) as min_sal
    ,a.* from employees a
    ) A
    where salary = min_sal;
    --Q2:
    select e.* ,(salary*1.10) as Bonus
    from (
    select dense_rank() over (partition by department_id order by hire_date nulls last ) as old_emp_rank
    , a.* from employees a
    order by a.employee_id,department_id desc) e
    where e.old_emp_rank = 1 ;
    --Q3:
    select count(*) over (partition by manager_id ) as cntofReportee,a.* from employees a;
    --4:
    select a.*, avg(salary) over (partition by department_id) from employees a where
    (months_between(sysdate ,hire_date) /12)> =12;

  • @shubhamthakur6256
    @shubhamthakur6256 4 года назад +1

    Brother, doing great job. Thanks a lot. Can you please also start making videos on plsql with real project examples as you always give??

    • @TechCoach
      @TechCoach  4 года назад

      Sure Shubham I will work on them

  • @amritamisra1878
    @amritamisra1878 5 лет назад

    Vivek...too good...very good explanation...it's worth watching your videos

    • @TechCoach
      @TechCoach  5 лет назад

      Thanks amrita for the kind words,I have a small request
      I am working on this new youtube channel, I Would love it if you watch and subscribe to it as well.
      ruclips.net/video/GnVn3mPBRz4/видео.html

  • @ranajparida5412
    @ranajparida5412 6 лет назад +1

    Hi Vivek,
    I was looking the vedio for the analytic function vedio no 19 and it was really good and help full.
    I jst want to ask you that you have not uploaded the next analytic vedio that might be helpful. I was searching that but still I am not getting it in your channel..
    If possible please upload it for which i will get notification.
    Really i am very much interested to get more and more knowledge on analytic function and much more about oracle...
    If you will publish the vedio class wise or pattern wise for every concept then i would be a great help for the people like me those who are very much interested to get knowledge..
    Please requesting you to upload the remaining vedio for analytic function for which it would be helpful.

    • @TechCoach
      @TechCoach  6 лет назад

      sure Ranaj, I will try to make some more, if you have specific question let me know .
      I am working on this new youtube channel"An Indian Abroad", please support me by watching subscribing and sharing.
      ruclips.net/user/AnIndianAbroadd

    • @ranajparida5412
      @ranajparida5412 6 лет назад

      I was totally viewing the vedio for partitions today...
      So please upload the remaining vedio for analytic function...

    • @TechCoach
      @TechCoach  6 лет назад

      sure, I will be really happy if you subscribe to my new channel as well.
      ruclips.net/user/AnIndianAbroadd

  • @piyush2010n
    @piyush2010n 2 года назад +1

    Amazing explanation

    • @TechCoach
      @TechCoach  2 года назад +1

      Thanks buddy, I have 4 more videos with practice exercise on this that may interest you

    • @piyush2010n
      @piyush2010n 2 года назад +1

      Can u help me know the playlist name

    • @TechCoach
      @TechCoach  2 года назад +1

      @@piyush2010n ruclips.net/video/7sJ3FooAuBE/видео.html
      You can start with this one

  • @venkatasaimounishennamuri1688
    @venkatasaimounishennamuri1688 6 месяцев назад

    It is very helpful !!! can't thankyou enough!

    • @TechCoach
      @TechCoach  5 месяцев назад

      Glad to hear that!

  • @vigneshnagaraj8001
    @vigneshnagaraj8001 5 лет назад

    That was an interesting piece of information. Many thanks!

  • @ahmedosman6285
    @ahmedosman6285 6 лет назад +2

    Thank you for the excellent explanation,
    I would like to ask you if the following query solve the fourth point in the exercise ?
    select b.* , avg(salary) over (partition by job_id order by hire_date range 4380 preceding) as Average_Salary
    from EMPLOYEES b
    ;

    • @TechCoach
      @TechCoach  6 лет назад

      Thanks for the kind words.I will review the query soon.
      I have a small request I am working on this new youtube channel "An Indian Abroad" it will really help me if you watch and subscribe to it.
      ruclips.net/video/HBQHekM1U2c/видео.html

  • @ursus9104
    @ursus9104 2 года назад +1

    So the main advantage is to avoid joins in your query, right. Now, I have a DataWarehouse 3rd normal form with 2000 tables, will AF be an advantage for me?

    • @TechCoach
      @TechCoach  2 года назад

      3rd normal in DW , your data would be highly normalized.
      If you fine yourself using self join often you can consider analytical functions.
      But with 3NF you mayn't get too much help with analytical functions.

  • @vedashwi
    @vedashwi 3 года назад +1

    thanks a lot..

    • @TechCoach
      @TechCoach  3 года назад

      You are welcome buddy :)

  • @gunalb1278
    @gunalb1278 2 года назад +1

    Hi bro I am fresher 2021 passed out student and I finished Oracle developer certification.And how to became a SQL developer what are the ways to finding jobs?please reply bro...

    • @TechCoach
      @TechCoach  2 года назад

      Hi Gunal,
      The job market is hot so you can find a job if you bring some "Value"
      Try learning SQL, Excel and one ETL or reporting tool, Polish your communication skills and apply at linkedln for every single job.
      All the very best

  • @sabilakhan3139
    @sabilakhan3139 5 лет назад +1

    ques: select oldest employee for each designation and give them 10% BONUS?
    SELECT ID,NAME, ROLE_ID, SALARY , CREATED_DATE, OLDEST,
    CASE WHEN OLDEST IS NULL THEN (SALARY*(10/100)) WHEN OLDEST IS NOT NULL THEN 0 END AS "BONUS" FROM
    (
    select a.id,a.name, a.role_id,a.salary, a.created_date, LAG(created_date) over (partition by role_id order by created_date) as "OLDEST"
    from employees a)
    order by id;
    Please let me know if the above is right

  • @prakashgour6087
    @prakashgour6087 2 года назад +1

    Thank you man..

    • @TechCoach
      @TechCoach  2 года назад

      Thanks Prakash , i am glad I could help
      Please consider subscribing to my other channel as well.
      ruclips.net/video/6G1xGi-D5ow/видео.html

  • @asavaripasalkar632
    @asavaripasalkar632 2 года назад +2

    where is the solution ? Please share it.. as I want to cross check my answers

  • @travelwithsrk
    @travelwithsrk 4 года назад

    Rest questions are simple but did not understand question no. 4.....in avg sal column, row who joined after 12 years should be null?

  • @mangavadivel6013
    @mangavadivel6013 4 года назад

    i tried question 2 with lag ... output not correct.
    hire_date in employees table is not in proper asec order.

  • @mangavadivel6013
    @mangavadivel6013 4 года назад

    thanks man ... it would really helps .. can u please post more videos with real time scenarios on DWH

  • @apharnashri
    @apharnashri 4 года назад

    awesome explanation on the analytical functions, Vivek !! Kudos !!

    • @TechCoach
      @TechCoach  4 года назад

      Thanks a lot for the kind words :)

  • @pradipawasthi2883
    @pradipawasthi2883 3 года назад

    Answer 1:-
    select * from(
    select a.*, min(a.salary) over(partition by job_id ) min_sal from employees a order by employee_id
    ) where min_sal in salary
    Answer 2:-
    select b.*,((b.salary*10)/100) as bonus from(
    select lead(hire_date) over(partition by department_id order by hire_date desc) oldest_joinee, a.* from employees a order by employee_id
    )b where oldest_joinee is null

  • @ambarkumar7805
    @ambarkumar7805 2 года назад

    Hi, at 5:15 I didn't gt why would we use a self join without self join we got the department wise avg sal

    • @TechCoach
      @TechCoach  2 года назад

      I meant that analytical function helps your do things which would other require a self join.

  • @nitingoalla
    @nitingoalla 6 лет назад +1

    Hey Vivek, you are doing a great job. Keep it up.
    Also, have you posted the solutions for the practice questions anywhere?

    • @TechCoach
      @TechCoach  6 лет назад +1

      Thanks for the kind words, I have not posted the answers but I will try and post soon.
      I have a small request I am working on this new youtube channel "An Indian Abroad" ,it will really help me if you watch and subscribe to it.
      ruclips.net/video/HBQHekM1U2c/видео.html

  • @CodeSipSociety
    @CodeSipSociety 2 года назад +1

    Best explanation 🔥

  • @vru5696
    @vru5696 2 года назад

    what if I want lead(hiredate) -1 in output . how to do this?

  • @yabuboys2879
    @yabuboys2879 6 лет назад +2

    hi
    your videos have good stuff, thanks for providing it in your channel.
    i have moderate knowledge in sql,plsql'
    but i don,t know how real time applications are build.
    will you please make a video in it.

    • @TechCoach
      @TechCoach  6 лет назад

      I would recommend watching my videos on DWH,ODS and star snow flake schema to get a basic idea, I will try to make some more

    • @TechCoach
      @TechCoach  6 лет назад

      I would love your support for my new channel, Please watch subscribe and share with your friends.
      ruclips.net/channel/UCoLdaMxhfDgdgIAcRGlUvkg

  • @Cookpe
    @Cookpe 4 года назад

    could you please guide for 2nd sample question. i'll try this but it gives min hire_date with all employees.

  • @santhoshgayakvad1013
    @santhoshgayakvad1013 6 лет назад

    Vivek , great explanation :) and good/simple examples to make us understand. Helps amateurs like me too to catch it quickly :)

    • @TechCoach
      @TechCoach  6 лет назад

      +Santhosh Gayakvad Thanks a lot buddy for the kind words :)

    • @TechCoach
      @TechCoach  6 лет назад

      I would love your support for my new channel, Please watch subscribe and share with your friends.
      ruclips.net/channel/UCoLdaMxhfDgdgIAcRGlUvkg

  • @vishwanathnikam8024
    @vishwanathnikam8024 5 лет назад +1

    SELECT COUNT(*) over (partition by MANAGER_ID),EMPLOYEE_ID, FIRST_NAME, LAST_NAME
    FROM Employees order by EMPLOYEE_ID ;
    is this the correct answer for question #3 ?

  • @srikamalit
    @srikamalit 4 года назад

    Video content is good. Using ORDER BY in the output would ease the readability and understanding.

    • @TechCoach
      @TechCoach  4 года назад

      Thanks a lot for the kind words:)

  • @giridandi7480
    @giridandi7480 Год назад

    Very nice

  • @varunguleria5960
    @varunguleria5960 3 года назад

    @Tech Coach: instead of using Lead , we could have used max of hire_Date partition by dept. to find recently hired person dept wise.
    WHAT SAY?

    • @TechCoach
      @TechCoach  3 года назад

      Yup you are right Varun, In fact in this video I have shown 3 ways of writing this query along with a lot of different queries
      ruclips.net/video/oiN8rfrWMwU/видео.html

  • @kumar-bi1to
    @kumar-bi1to 2 года назад

    Excellent 👌

  • @vikastiwari6564
    @vikastiwari6564 4 года назад

    Can you please let us know that how to install the same set of data and table in personal laptop?
    This video is so knowledgeable and it helped a lot in order to Analytical functions!! Would like to appreciate your efforts!!!

    • @TechCoach
      @TechCoach  4 года назад

      Sure Vikas , I will be uploading a video later today.

    • @vikastiwari6564
      @vikastiwari6564 4 года назад

      @@TechCoach Waiting for it

  • @itzzzzpandit
    @itzzzzpandit 6 лет назад +1

    Hello. At 17.40 scenario, please try without giving order by clause. i think output will be different. Thanks

    • @TechCoach
      @TechCoach  6 лет назад

      you need to specify order by clause in almost every analytical function other wise it will give you an error.
      Please help me in building my new channel by subscribing sharing and watching.
      ruclips.net/user/AnIndianAbroadd

    • @khobareamol7215
      @khobareamol7215 5 лет назад

      @@TechCoach But I don't think below will give error,
      SELECT SUM(SALARY) OVER( ) CUM_SAL, E.* FROM EMPLOYEES E

    • @TechCoach
      @TechCoach  5 лет назад +1

      @@khobareamol7215 yes sir, you are right that's why I wrote "Almost".

  • @manishbatta6603
    @manishbatta6603 4 года назад

    bro best video .Subscribed it best content on youtube regarding SQL

    • @TechCoach
      @TechCoach  4 года назад

      Thanks manish for the kind words, I have a small request.
      I am working on this new RUclips channel.I would really appreciate if you watch and subscribe to it.
      Your support is my motivation.
      ruclips.net/video/0sLU8YaYr4w/видео.html

  • @pankajrao6486
    @pankajrao6486 5 лет назад

    Thanks a lot for detailed explanation....

    • @TechCoach
      @TechCoach  5 лет назад

      Thanks Pankaj for the kind words. I am working on this new channel and would really appreciate if you watch and subscribe to it.
      ruclips.net/video/IP2Vn6jK8Hg/видео.html

  • @bhavanapriyankazanavarapu869
    @bhavanapriyankazanavarapu869 6 лет назад

    you are explaining awsome sir...

    • @TechCoach
      @TechCoach  6 лет назад

      Bhavana Priyanka zanavarapu Thanks a lot for the kind words :)

    • @TechCoach
      @TechCoach  6 лет назад

      I would love your support for my new channel, Please watch subscribe and share with your friends.
      ruclips.net/channel/UCoLdaMxhfDgdgIAcRGlUvkg

  • @1212wolverine
    @1212wolverine 6 лет назад

    superb explanation. Thank you.

    • @TechCoach
      @TechCoach  6 лет назад

      Thanks a lot for the kind words :),
      I Would really appreciate if you help me build my new channel by watching subscribing and sharing "An Indian Abroad".
      ruclips.net/channel/UCoLdaMxhfDgdgIAcRGlUvkg

  • @mangavadivel6013
    @mangavadivel6013 4 года назад

    also i tried 2nd question from ur assignment (oldest employee department wise) using min(hire_date) ... output comes with multiple different date for each department.

    • @ranajparida3902
      @ranajparida3902 4 года назад

      Bro the recent employee,we can get by max(hiredate)

  • @aishwaryapattnaik3082
    @aishwaryapattnaik3082 5 лет назад +1

    Can you post the answers too for the sample problems :)
    Do you have any forum to contact in case of any doubts.

  • @abhishekvedula340
    @abhishekvedula340 5 лет назад

    clear as crystal...thank you :)

    • @TechCoach
      @TechCoach  5 лет назад

      Thanks Abhishek for the kind words, It means a lot to me. I have a small request, I am working on this new channel and would really appreciate if you watch and subscribe to it.
      ruclips.net/video/IP2Vn6jK8Hg/видео.html

  • @sameerkumarpatro5569
    @sameerkumarpatro5569 6 лет назад

    One question - For cumulative salary you didn't mention the significance of "Order By" in over() clause, which is most imp. This would explain how sum function provides cumulative sum.

    • @TechCoach
      @TechCoach  6 лет назад

      Thanks sameer, I will review what I have mentioned.
      I have a small request I am working on this new youtube channel " An Indian Abroad " and will really appreciate if you watch and subscribe to it.
      ruclips.net/video/11DK-oyRql0/видео.html

  • @rafdnaah6078
    @rafdnaah6078 5 лет назад +1

    You can use this query to find the recent joinee:
    SELECT department_id
    , max (hire_date) recent_hiredate
    , min (employee_id) keep (dense_rank first order by hire_date desc) recent_employee_id
    FROM employees GROUP BY department_id ORDER BY department_id;
    for a more detailed resultset, use this
    SELECT department_id
    , MAX(hire_date) recent_hiredate
    , MAX(employee_id) KEEP (DENSE_RANK FIRST ORDER BY hire_date DESC) recent_emp_id
    , MAX(last_name) KEEP (DENSE_RANK FIRST ORDER BY hire_date DESC) recent_last_name
    , MAX(first_name) KEEP (DENSE_RANK FIRST ORDER BY hire_date DESC) recent_first_name
    FROM employees GROUP BY department_id ORDER BY department_id;

  • @sakshinema8602
    @sakshinema8602 4 года назад

    Commendable. Thanks a lot for this video :)

    • @TechCoach
      @TechCoach  4 года назад +1

      Thanks a lot Sakshi, this video on Indexing may interest you as well :).
      ruclips.net/video/0X9bbtwTnuE/видео.html

  • @daves4026
    @daves4026 4 года назад

    Great tutorial

    • @TechCoach
      @TechCoach  4 года назад

      Thanks Dave for the kind words :)

  • @kashifihsan
    @kashifihsan 6 лет назад +1

    Hi, can you plz make a video on listagg.

    • @TechCoach
      @TechCoach  6 лет назад

      Please check this video it should help .
      ruclips.net/video/-DDBt48G2ug/видео.html
      I have a small request I am working on this new youtube channel
      "An Indian Abroad"
      It will really help me if you watch and subscribe to it
      ruclips.net/user/AnIndianAbroadd

  • @ankitapathak2371
    @ankitapathak2371 4 года назад

    Very nice sir 👍

    • @TechCoach
      @TechCoach  4 года назад +1

      Thanks a lot Ankita for the kind words :)

  • @rhari09
    @rhari09 6 лет назад

    Hi.., the explanation is clear.
    But can you please tell on sum(salary) using order by employee gives sum of last two employees like window function.
    Similarly i am confused on window as avg is done three rows where we require only for two rows
    Please explain
    Does order by clause has these effects?

    • @TechCoach
      @TechCoach  6 лет назад

      I would love your support for my new channel, Please watch subscribe and share with your friends.
      ruclips.net/channel/UCoLdaMxhfDgdgIAcRGlUvkg

  • @pritamdutta8092
    @pritamdutta8092 4 года назад +1

    Answer for homework:
    1.select minimum_salary over (partitions by designation) as minimum_salary_by_des, e.* from (select min(salary) over(partition by department order by salary) as minimum_salary , a.* from employee a ) e;
    2.select max(hire_date) over (partition by department order by hire_date) as oldest_employee , a.* from employee a ...after this how to proceed ?
    3.select count(employee_id) over(partition by manager_id) as total_number_of_employee , a.* from employee a
    I know i am wrong on 2 and 3 one Please correct me what is the exact answer. I dont have toad or plsql developer with my right now.

    • @sehajshangari5707
      @sehajshangari5707 3 года назад

      select * from emp where (empno,deptno,sal) in (
      select empno,deptno, min(sal) over (partition by job order by sal) T from emp a)
      select a.*,sal*1.1 as bonus from emp a where (empno,deptno,hiredate) in
      (select empno,deptno,min(hiredate) over (partition by deptno order by hiredate) H from emp)
      select a.*,count(empno) over (partition by mgr) from emp a order by mgr asc

  • @ishikabansal9231
    @ishikabansal9231 4 года назад

    If we need the count of distinct entries of a table without using the column name, can we do it using Analytic functions without any join?

    • @TechCoach
      @TechCoach  4 года назад

      Select count() over (),e.* from employees.
      I am guessing this is what you are looking for ishika

    • @ishikabansal9231
      @ishikabansal9231 4 года назад

      @@TechCoach It will give me the total count of the rows of the table but I need distinct rows, can you tell me how can I implement that?
      I need a simplified version of this command :
      select count(*) from (select distinct(*) from employees)

  • @fathimarizwana9909
    @fathimarizwana9909 5 лет назад

    thank u for ur useful video...in the sample scenario u asked to , Select the details of employees with minimum salary on their designation...i got the query as follows ---- select a.*,min(salary) over (partition by job_id) from employees a order by job_id;but it still retrieves multiple JOB_IDs with all salary ....BUt it need to the minimum salary according to each designation...how to correct it??pls calrify

    • @TechCoach
      @TechCoach  5 лет назад

      I will take a look at the query Fathima and will get back to you soon, you haven't specified the order by clause along with partition by but that shouldn't cause any issues.
      Meanwhile I have a small request, I am working on this new channel and would really appreciate if you watch and subscribe to it.
      ruclips.net/video/IP2Vn6jK8Hg/видео.html

  • @ashutoshsharma3396
    @ashutoshsharma3396 6 лет назад

    sum(salary) : it should give total sum of salary department wise, for cumulative sum i think we add 'rows unbounded preceding' in analytical function, can you please clear my doubt.

    • @TechCoach
      @TechCoach  6 лет назад +1

      Great Question Ashutosh.
      First Explanation:
      once you have used partition by department that means the sum function will be applied on individual departments, now here order by is of vital importance actually because of it the 1st row doesn't have any preceding row so we will get just its salary sum, the 2nd row will have 1 preceding row so it will have the sum of 1st and itself and so on. Try running the query on your own it will give you the correct values.
      Rows unbounded preceding : yes you are right there are multiple ways to achieve the same result you can use Rows unbounded preceding clause instead of partition by departments to obtain the same result, In Rows unbounded preceding the order by clause is used to describe the window instead of ordering.
      sum(salary) over (order by dept_no rows unbounded preceding) cum_sum
      will give you cum_sum of salary department_wise, Because here it will continue to do cum_sum as long as it find the same dept_no, As soon the dept_no changes it will again cum_sum for that dept.So here order by is acting as a windowing function instead of ordering.
      I hope this clarifies your doubt, I have a small request I am working on this new youtube channel "An Indian Abroad "
      and it will really help me if you watch and subscribe to it.
      ruclips.net/video/HBQHekM1U2c/видео.html
      Please share it with your friends as well, your support is my motivation.

  • @samvedna7153
    @samvedna7153 4 года назад

    Do provide feedback.
    1.select min(salary) over(partition by job_id) as min_sal , a.* from employees a
    order by a.job_id;
    2.select employee_id,department_id, hire_date,salary , salary * 1.1 from
    (select a.*,rank() over(partition by department_id order by hire_date ) as old_emp from employees a
    order by a.department_id,a.hire_date)
    where old_emp=1;
    3. select count(employee_id) over(partition by manager_id) as count_emp , a.* from employees a
    order by a.manager_id;
    4.select avg(salary) over(partition by job_id) ,a.* from employees a where add_months(trunc(sysdate) , -12*12) > a.hire_date

    • @siprabehera4680
      @siprabehera4680 4 года назад

      2.select * from (select lag(hiredate) over (partition by deptno order by hiredate) old_emp,sal*.10 bonous_sal,e.* from emp e) where old_emp is null
      try this

  • @amareshgangal7
    @amareshgangal7 6 лет назад

    Very Good Series..

    • @TechCoach
      @TechCoach  6 лет назад

      Thanks Amaresh for the kind words :), I hope you share it with your team and friends as well :)

    • @TechCoach
      @TechCoach  6 лет назад

      I would love your support for my new channel, Please watch subscribe and share with your friends.
      ruclips.net/channel/UCoLdaMxhfDgdgIAcRGlUvkg

  • @satheeshy2k
    @satheeshy2k 5 лет назад

    Hi ..nice video about analyitcal functions..thank you...instead of "lead(hire_date)" can'nt we use "max(hire_date)" after partitioning by as below :
    select MAX(hire_date) OVER(PARTITION BY department_id) ,a.* from employee a

    • @TechCoach
      @TechCoach  5 лет назад

      HI Sateesh in this particular case max can be used, but max and lead are very different functions in general.
      Let's say I am trying to analyze how my aircarft flies throughout the day.
      Source|Dest|dept|arrival|aircraft_type
      Delhi|Mumbai|7:00|9:00|787
      Chennai|Hyderabad|14:00|16:00|787
      Mumbai|Chennai|10:00|12:00|787
      Hyderabad|Delhi|17:00|19:00|787
      I can use lead function here to identify my aircraft positions which can't be done using max.
      I hope this clarifies the difference.
      I need a small help I am working on this new youtube channel and would really appreciate if you watch and subscribe to it.
      ruclips.net/video/11DK-oyRql0/видео.html

    • @satheeshy2k
      @satheeshy2k 5 лет назад

      Got u !!! Appreciate your quick response

    • @TechCoach
      @TechCoach  5 лет назад

      Thanks Satheesh I am happy I could help.

    • @PinkFloydTheDarkSide
      @PinkFloydTheDarkSide 5 лет назад

      @@TechCoach - But your logic of using LEAD will fail if there are multiple people with the same hire date in the same department. I used RANK() which I think works better here because the same RANK is assigned to multiple rows if they have the same value for the concerned column.

  • @sivajajula2808
    @sivajajula2808 4 года назад

    many many thanks

    • @TechCoach
      @TechCoach  4 года назад

      Thanks Siva for the kind words :)

  • @AdityaVermaopenheartedme
    @AdityaVermaopenheartedme 4 года назад

    Hi great video on analytical functions, just got one issue.
    In the video, at 22:18 you said that it is going to compute the average salary of Neena by taking average of three salaries, whereas the function is row 2 preceding, should not it be calculating the average salaries only using only 2 prior salaries, the salary of Neena and only one before her?
    Please give clarification.

    • @TechCoach
      @TechCoach  4 года назад +1

      Hi Aditya, why don't you try running the statement in oracle once? I think that will clarify all your doubts.
      If you still have any questions please do let me know. I will be happy to help :)

    • @AdityaVermaopenheartedme
      @AdityaVermaopenheartedme 4 года назад

      @@TechCoach Sure! Thanks for your reply. Also, if you have time please make an extended video on this topic, explaining everything, every function.
      Thanks

    • @TechCoach
      @TechCoach  4 года назад +1

      @@AdityaVermaopenheartedme Sure I will work on it :)

    • @AdityaVermaopenheartedme
      @AdityaVermaopenheartedme 4 года назад

      @@TechCoach could you please recommend some good resource?

    • @TechCoach
      @TechCoach  4 года назад +1

      @@AdityaVermaopenheartedme you can check asktom on google, there is a course on udemy that explains analytical functions in detail as well. I will try posting some practice scenarios in the next couple of days.

  • @nikhar1234tare
    @nikhar1234tare 5 лет назад +1

    Is it possible to find nth highest/lowest salary by using analytical function?

    • @TechCoach
      @TechCoach  5 лет назад

      yes it is and it's pretty easy,
      select * from (
      select rank() over (order by salary) as rank1,e.* from employees
      ) where rank1=n
      please let me know if it helps.
      I have a small request I am working on this new channel "An Indian Abroad "
      I will really appreciate if you watch and subscribe to it.
      ruclips.net/video/IR6mVE181a4/видео.html

    • @niharranjandash7004
      @niharranjandash7004 5 лет назад

      NO

    • @a_mhite2
      @a_mhite2 5 лет назад

      @@TechCoach Small mistake in above query.. Corrected in below..
      Select * FROM
      (Select RANK() OVER(Order By Salary ASC) as Latest_Rank, e.* From employees e) Where Latest_Rank=&N;

    • @malliarjun5250
      @malliarjun5250 4 года назад

      @@a_mhite2
      Don't use rank function if you use rank
      24000 1
      17000 2
      17000 2
      14500 4
      If u want 3rd rank salary we don't get it
      So use dense_rank function
      Then we can query for whatever rank we want
      24000 1
      17000 2
      17000 2
      14500 3

    • @malliarjun5250
      @malliarjun5250 4 года назад

      @@a_mhite2
      Use desc in order by that too in dense_rank() function

  • @enockoloo3814
    @enockoloo3814 4 года назад

    this is great

    • @TechCoach
      @TechCoach  4 года назад

      Thanks Enock for the kind words :)

  • @pankajkharade6936
    @pankajkharade6936 4 года назад

    superb

    • @TechCoach
      @TechCoach  4 года назад

      Thanks Pankaj for the kind words :)

  • @iticcl3565
    @iticcl3565 6 лет назад

    Hi.. have any idea to know how can i find Query to generate Employee absent report for a given range of dates
    but.. not possible to query.. can you help me.

    • @TechCoach
      @TechCoach  6 лет назад

      Can you please elaborate a lil more?

    • @TechCoach
      @TechCoach  6 лет назад

      I Would really appreciate if you help me build my new channel by watching subscribing and sharing "An Indian Abroad".
      ruclips.net/channel/UCoLdaMxhfDgdgIAcRGlUvkg

    • @iticcl3565
      @iticcl3565 6 лет назад

      im working in RMG sector in Bangladesh as a IT person.. every month many people absent continuously like 5 or more days.. so i calculate in those employe who absent continuously basent five or more days in a month ... i can't do this. I need your help to find out this.

    • @TechCoach
      @TechCoach  6 лет назад

      Can be done using analytical function or a stored procedure both. I can share it with you after 15 days as I am on vacation right now.

    • @iticcl3565
      @iticcl3565 6 лет назад

      can u share me your mail address. i send you query with database..

  • @sudheereddy6182
    @sudheereddy6182 6 лет назад

    Can I have the ddl & dml for the tables explained above pls ...

    • @TechCoach
      @TechCoach  6 лет назад

      Hi Sudhee, Unfortunately I don't have it handy right now, Majority of the tables used here are standard HR schema tables which comes by default when you install oracle express edition.
      I would recommend installing oracle express edition and trying the queries shown in video on those tables.
      I have a small request I am working on this new youtube channel "An Indian Abroad" ,it will really help me if you watch and subscribe to it.
      ruclips.net/channel/UCoLdaMxhfDgdgIAcRGlUvkg

  • @hanifouladgar7842
    @hanifouladgar7842 4 года назад

    Where can I find the data and the answer to the questions?

    • @TechCoach
      @TechCoach  4 года назад

      Hi Hani, most of the answers are posted in the comments section.

  • @akshaykumarjain7011
    @akshaykumarjain7011 3 года назад

    Thanks

  • @mangavadivel6013
    @mangavadivel6013 4 года назад

    can you provide answers for those 4 assignment questions.

    • @TechCoach
      @TechCoach  4 года назад

      @Manga , Quite a few people havd answered them in comments. If you don't find them helpful please let me know I will be more than happy to provide them

    • @mangavadivel6013
      @mangavadivel6013 4 года назад

      @@TechCoach i tried question 2 with lag ... output not correct.

  • @mangavadivel6013
    @mangavadivel6013 4 года назад

    I tried round (avg(salary)). it didnot work. why?

    • @TechCoach
      @TechCoach  4 года назад

      Can you post the query please?

    • @mangavadivel6013
      @mangavadivel6013 4 года назад

      @@TechCoach select e.*, round(avg(salary)) over(partition by department_id order by salary ) avg_sal from employees e ;
      shows from keyword not found where expected.

    • @shivkanyashinde1607
      @shivkanyashinde1607 4 года назад

      query should be like
      select e.*,
      round(avg(e.salary) over(partition by e.department_id order by e.hire_date)) as avg_sal from employees e;

    • @shivkanyashinde1607
      @shivkanyashinde1607 4 года назад

      have to use round function to complete analytical function not only for the avg function

  • @rubang973
    @rubang973 3 года назад

    Grt❤️

  • @deeek92
    @deeek92 6 лет назад +1

    Can you please post the answers as well

    • @TechCoach
      @TechCoach  6 лет назад

      Deepankar Kotnala Sure I will post them soon :)

    • @deeek92
      @deeek92 6 лет назад

      Tech Coach okay..thanks :)
      We want to match our queries with the solutions provided by you :)

    • @TechCoach
      @TechCoach  6 лет назад

      I would love your support for my new channel, Please watch subscribe and share with your friends.
      ruclips.net/channel/UCoLdaMxhfDgdgIAcRGlUvkg

  • @RenuSharma-rx8yt
    @RenuSharma-rx8yt 4 года назад

    Pls anyone tell me how to solve this --> Q. The percentage of people who were handraisers for each campaign. For reference this is the table - Table: user_handraisers
    +--------------------------+--------+---------+
    | name | type | comment |
    +--------------------------+--------+---------+
    | campaign_date | string | |
    | userid | string | |
    | campaign_id | string | |
    +--------------------------+--------+---------+

  • @shanmugaraj09
    @shanmugaraj09 5 лет назад

    Crazy 😘

    • @TechCoach
      @TechCoach  5 лет назад

      Thanks Shanmuga for the kind words I have a small request
      I am working on this new youtube channel, I Would love it if you watch and subscribe to it as well.
      ruclips.net/video/GnVn3mPBRz4/видео.html

  • @navk4960
    @navk4960 4 года назад

    video blurr

    • @TechCoach
      @TechCoach  4 года назад

      Can you please try watching the video at 1080p?

    • @navk4960
      @navk4960 4 года назад

      @@TechCoach my display on laptop is set with highest 1366 X 768

    • @navk4960
      @navk4960 4 года назад

      watched other video of yours, didn't see any issues with that..

    • @TechCoach
      @TechCoach  4 года назад

      Oh I am sorry :(

  • @pramodchamute8882
    @pramodchamute8882 4 года назад

    Not a good explain

    • @TechCoach
      @TechCoach  4 года назад

      I am sorry pramod, I will try to do better next time.

  • @ilovemyindia54
    @ilovemyindia54 2 года назад

    Sir apka number do

  • @KrishnaPaneri
    @KrishnaPaneri 6 лет назад

    Thanks... Nicely explained

    • @TechCoach
      @TechCoach  6 лет назад

      Thanks a lot for the kind words.
      I would really appreciate if you help me in my new Initiative "An Indian Abroad"
      by subscribing viewing and sharing.
      ruclips.net/user/AnIndianAbroadd