How to Calculate Mode in SQL | How to Find Most Frequent Value in a Column

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

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

  • @RoshniNV-v3d
    @RoshniNV-v3d 2 месяца назад +1

    This was asked in my interview yesterday, I wish I had watched this earlier, but now I’m damn sure I won’t forget how to tackle these kind of problems ,thank you so much Ankit bhaiya 💯

  • @divyaaggarwal7824
    @divyaaggarwal7824 2 года назад +8

    I am preparing for interviews and I just came across your channel. The videos are really informative. Thankyou so much !! 👍🏻
    Keep up the good work, buddy.

  • @gauravpanchariya
    @gauravpanchariya Месяц назад

    Your videos are really helpful in preparation of SQL. I subscribed your channel to learn more and in detail about SQL.

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

    Great solutions in simple way. I would like to share my interview experience.. This was the 1st questions asked in OPTUM(UHG) interview.. both using SQL & Tableau ..
    @Ankit your videos are really very helpfull in clearing concepts & basics .. keep up the good work :)

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

    Thanks Brother for your precise explanation,though I had the knowledge about joins still I got some useful insights.

  • @hairavyadav6579
    @hairavyadav6579 Месяц назад

    Hello sir please let me know this will work or not
    with cte as(select *,row_number() over(partition by id) rnk from mode)
    select id from cte where rnk in (select max(rnk) from cte);

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

    with cte as(
    select id, row_number() over (partition by id order by id) most_time from mode)
    select * from cte where most_time =
    (select max(most_time) from cte)

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

      I'm thinking about using row_number() as well because there will only be only one record in output this way

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

    Great explanation sir, I have also solved it but using subquery and rank function without CTE

  • @anishchhabra6085
    @anishchhabra6085 10 месяцев назад +2

    Excellent explanation bro! I think instead of 2 cte's we can use this code
    with cte as
    (
    select *,
    rank() over(order by count(id) desc) as rnk
    from mode
    group by id
    )
    select id
    from cte
    where rnk = 1;

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

    cte as (select id, rank() over (order by count(*) desc) rwn from mode group by id)
    select * from cte where rwn =1

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

    Much helpful! Thanks for putting it up

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

    Can you please make videos on python and ML

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

    Thanks... Great video

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

    Good Ankit

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

    Thanks

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

    thank you

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

    ;WITH cte
    AS (SELECT id,
    RANK() OVER (ORDER BY COUNT(id) DESC) AS RNK
    FROM dbo.mode
    GROUP BY id)
    SELECT id
    FROM cte
    WHERE RNK = 1;

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

    SELECT TOP 1 WITH TIES *,COUNT(1) AS frequency FROM mode
    GROUP BY id
    ORDER BY COUNT(1) DESC;

  • @vishalsonawane.8905
    @vishalsonawane.8905 6 месяцев назад

    Done

  • @rishikeshdwivedi-x1r
    @rishikeshdwivedi-x1r Год назад

    Here is my Code:
    select top 1 id, count(*) as Frequency from mode
    group by id order by count(*) desc

    • @GiriPrasath.D
      @GiriPrasath.D 7 месяцев назад

      select top 1 id, count(*) as Frequency from mode
      group by id
      order by frequency desc

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

    With you sql seems piece of cake

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

      It is piece of cake if you understand fundamentals 😊

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

    select id, count(id) as occurrences from modes group by id having count(id) = (select max(count(id)) from modes group by id)
    How about this?

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

      with cte as
      (select id,count(*)as m from mode1 group by id order by M desc)
      select id,M from cte where M=(select max(M) from cte)

    • @sz6618
      @sz6618 2 месяца назад +1

      nested aggergation not allowed

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

      ​@@sz6618 what?

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

      @@armanmardhani8963 max and count both are aggregate function. You can not use both function together in SQL. In BI tool it's possible