Pivoting Data with SQL

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

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

  • @soodvarun20
    @soodvarun20 Год назад +2

    Another way of doing this using CASE method is
    select
    ReleaseYear,
    count(distinct case when Genre='Sci-Fi' then Title* else null end) as 'Sci Fi',
    count(distinct case when Genre='Crime' then Title* else null end) as 'Crime',
    count(distinct case when Genre='Romance' then Title* else null end) as 'Romance',
    count(distinct case when Genre='Action' then Title* else null end) as 'Action',
    count(distinct case when Genre='Drama' then Title* else null end) as 'Drama'
    from movies
    group by 1
    order by 1;
    * (Title or MovieId . either of the can be taken in case statement as both will be unique )

  • @tjw52x
    @tjw52x 11 месяцев назад +1

    Interesting video, thanks. Just wondering though, is there a way to do dynamic pivoting, so that you don't have to type out the values in the columns - in the case where you have a lot of different values in the columns?

  • @saveeshmply
    @saveeshmply 3 месяца назад +1

    Thank you . Was helpful for me :)

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

    That’s cool! Been using SQL for almost 2 years now and love learning stuff like this!

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

    Thank you for sharing