T-SQL Tutorial - PIVOT without using PIVOT

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

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

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

    Very well illustrated. If you like PIVOT, stick with it, but this is certainly an alternative, especially if the other columns have slightly different conditional aggregations. Well done sir!

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

    Glad I found your channel. Precisely what I was looking for. Subscribed immediately and activated the 🔔. Excellent subject selections. Keep them coming and THANK YOU for all efforts and time!

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

    This is a great way to find sums and averages, etc. Thanks for the pro-tip!

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

    Thanks, I was very helpful.

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

    This actually fits my solution better than pivot table.

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

    Not a fan of the Pivot syntax personally, but then I couldn't offer a better alternative! Pivoting by using case and aggregating is the way you would always accomplish this before they introduced the Pivot syntax, which as you point out, is just using the traditional case implementation anyway. I have used Pivot a few times to accomplish a more compact syntax which actually helps make other parts of the query easier to follow, however following what's going on with a Pivot someone else has written or even yourself in the past I find more challenging than if it were cased, particularly if it's used in dynamic sql, often the case for reporting where the columns aren't known in advance. Plus of course using case gives you far more control that you don't have with Pivot and is easier to debug and modify, in my experience this is also needed more often than not - at least with the user requirements I tend to encounter!

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

      Excellent points, I didn’t want everybody to think they should avoid using Pivot, it is still useful.

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

    Can we have videos on how to calculate Month over Month, week over week and year over year metrics?

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

      Great idea, I will put it on the list.

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

    Ingenious! What more needs to be said?

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

    why do we have use sum here , without using the sum logic seems correct to me

    • @BeardedDevData
      @BeardedDevData  11 месяцев назад

      I understand where you are coming from but because we are grouping data we need to use an aggregate function otherwise the query would fail.

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

    I may NEVER use the much maligned Pivot command again!