Aggregation and Window Functions Together in a Single SQL | Advance SQL

Поделиться
HTML-код
  • Опубликовано: 13 дек 2024

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

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

    Simplest Solution:
    select category, product_name, sales from
    (
    Select category, product_name, sum(sales) as sales,
    rank() over(partition by category order by sum(sales) desc) rnk
    from [dbo].[Sample - Superstore.xls - Orders] group by category, product_name
    ) x
    where x.rnk

  • @akashsonone2838
    @akashsonone2838 Год назад +4

    Hi Ankit, CSV files seems deleted, is it?

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

    Very nice vdo 😇😇 ❤❤

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

    Hey @Ankit thanks for posting this. In today's morning I was scrolling RUclips for this type of questions.

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

    I can't believe you explain this topic so easily 😲 Thanks

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

    Nice.
    Do we have any advantage of doing it this way? other than removing cte in the code.

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

      Nothing more advantageous. Just wanted to tell you another way of doing it.

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

      I just fix the sql as their was typo .initially I tried using cTE later I tried without CTE

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

    Thank you for this playlist ankit bhai.. Really helpful

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

    Hi Ankit,
    your videos are excellent. They cleared most of my doubts.
    Can you make video on denormalization or normalization(breaking a row to multiple rows) of table through sql?
    Also on unions ?
    Thanks

  • @vandanaK-mh9zo
    @vandanaK-mh9zo Год назад

    Insights - when you do GROUP BY and RANK() in the same query, order of execution will be as follows :
    GROUP BY -> AGGREGATION FUNCTION --> RANK()

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

    Hi Ankit,
    Great video
    Kindly create a video on SQL cursors.
    I was going through your channel for cursor video but couldn't find it

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

    Nice explanation 👌 👍 👏

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

    Thank u Ankit for your efforts . if you can provide tables data for used in those videos then very helpful for us

  • @vibhavaribellutagi9738
    @vibhavaribellutagi9738 Год назад +1

    Thanks a lot for this amazing video. BTW, the dataset link isnt working. :)

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

    Hey there, god bless your efforts.
    I am still learning about sql by my own and having today a simple question.
    I learned that Processes (also known as “procedures”) may take values and give
    out parameters.
    Are processes opposite of a function?
    Is there any related functions used to execute a process? Thanks..

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

    using dense_rank:
    with top_sales_per_cat as(
    select
    category,
    Product_Name ,
    sum(Sales) as Total_Sales,
    DENSE_RANK() over(partition by Category order by SUM(sales) desc) as rn
    from
    market_star_schema.`sample - superstore`
    group by
    Category,Product_Name
    )
    select * from top_sales_per_cat
    where rn

  • @SACHINKUMAR-px8kq
    @SACHINKUMAR-px8kq Год назад

    Thankyou so much Sir for this Amazing Class

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

    Thanks for this

  • @raviraj-xq4ue
    @raviraj-xq4ue 2 года назад +1

    ankit bhaiya , ek question pucha aaj mere se in sql interview - 4 columns hn ID, s1, s2,s3(ye teen subjects hn jike marks diye rhenge) mjhe top student nikalna h jiska s1+s2+s3 max ho using dense_rank().
    so maine ye query try ki - SELECT id, s1+s2+s3 as summ, dense_rank() as rank over(order by summ desc ) FROM students-;
    but ye kaam nhi kiya, can u pls tell kya solution hoga iska

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

      with cte as(
      select *, s1+s2+s3 as max_marks from students)
      select *, dense_rank() over(order by max_marks desc) as rn from cte;

    • @v.bhavana671
      @v.bhavana671 2 года назад +1

      @ravi Raj , sum is work with column data not with row data
      Which means u can't add subj marks for each student individually by using sum() function.
      @ankit bansal , will help us to find a proper solution for it
      Thanks in advance 🤗

    • @sz6618
      @sz6618 3 месяца назад

      Create table #TopMarks ( ID int, S1 INT,S2 INT, S3 INT)
      INSERT INTO #TopMarks Values (1,100,200,300), (2,100,20,30), (3,200,200,300)
      Select * from #TopMarks
      Select ID,(S1+S2+S3) as [Top],
      RANK() over ( order by S1+S2+S3 desc)
      from #TopMarks

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

    hi ankit sir,
    Im getting issue in importing data in mysql workbench out of all the rows only 27 or 140 is importing in my sql workbench. i have checked everthying data types and file formate everything..? what to do

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

    Hi your vdos are very beneficial. And watch ur vdos frequently and your suggestions on linkdin...i am a mechanical engineer working in a psu. May be you know that all psus are in remote location far from city life no social life. I want transition from power engineer to data science or data analyst..i have learnt baisc of python,sql some of libraries like pandas,numpy....pls guide me with some suggestions....
    And, is it easy or possible to get a job work from home in dataanalyst. Thanks....

  • @rabink.5115
    @rabink.5115 2 года назад

    Hi Ankit, could you please tell why dense_rank not worked in your previous problem( air bnb cross apply). I posted there but no response for any one.

    select value as rm_type, count(*) as no_search,
    dense_rank() over( order by count(*) desc) as rnk
    from airbnb cross apply string_split(filter_room_types, ',')
    group by value
    having rnk = 1;

  • @as-youtuber6215
    @as-youtuber6215 2 года назад +7

    Bro when are we starting our python series. Waiting for so long 😭

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

    Nice

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

    I want to get count of missing states for an column by using count and lag in same query with group by.. Is the scenario possible?

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

    data set link not working deleted

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

    @ankit bansal sir please share csv file

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

    Hi , I see your videos are very good and I do have one business problem , pls write the sql .
    In put
    Caller Reciever call_duration(sec)
    Raj Ram 30
    Ram Raj 60
    Robert Raheem 50
    Arun Raj 45
    Raj Arun 25

    Out put
    Caller1 Caller2 no_of_calls total_duration
    Raj Ram 2 90
    Arun Raj 2 70
    Robert Raheem 1 50
    pls let me know if you need more details.

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

      select least(caller,receiver) as Person1,greatest(caller,receiver) as Person2 ,count(1) as no_of_times,total_sec
      from cte
      group by 1,2;
      Script :
      create table caller_receiver(
      caller varchar(20),
      receiver varchar(20),
      call_duration_sec int
      );
      Insert into caller_receiver values ('Raj','Ram',30);
      Insert into caller_receiver values ('Ram','Raj',60);
      Insert into caller_receiver values ('Robert','Raheem',50);
      Insert into caller_receiver values ('Arun','Raj',45);
      Insert into caller_receiver values ('Raj','Arun',25);

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

      select least(caller,receiver) as Person1,greatest(caller,receiver) as Person2 ,count(1) as no_of_times,sum(call_duration_sec)
      from caller_receiver
      group by Person1,Person2;

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

    Sir pls start a paid course on sql