How to Add a Row Number to Your SQL Query Using row_number and partition by

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 พ.ย. 2024

ความคิดเห็น • 22

  • @jimmyahmadu
    @jimmyahmadu 2 หลายเดือนก่อน +1

    how do you update your table with the serial row number

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  หลายเดือนก่อน

      Well, the row number is calculated, so you can just update your table and then re-run the query to get the new row numbers. If you want the numbers to be static after you generate the query, perhaps insert the results into a temp table or something like that, then work on that table.

  • @DCh-ks6ug
    @DCh-ks6ug 4 หลายเดือนก่อน +1

    is it necessary to use order by function in the row_number function ?

  • @USA_to_Asia_in_2024
    @USA_to_Asia_in_2024 4 หลายเดือนก่อน +1

    GREAT explanation.

  • @sonathena3150
    @sonathena3150 2 ปีที่แล้ว +1

    Hello Sean, do you have a copy of the dataset in this discussion? I hope you do have so we can try it by ourselves. Thanks

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  2 ปีที่แล้ว +2

      Yes I'll take a look today and see! You will need to put it on your SQL Server. Thanks!

  • @sarahgorton8927
    @sarahgorton8927 2 ปีที่แล้ว +1

    very well explained, thank u!

  • @Oleemil89
    @Oleemil89 5 หลายเดือนก่อน +1

    Nice video! I enjoyed the intro song, but people have different expectations i guess. Who is playing and what song is it? Had a nice riff

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  5 หลายเดือนก่อน

      I believe that track was called "Ripped" and was included with license as part of the Camtasia studio selections.. 2019 or 2020 version iirc. I thought it was groovy!

  • @diegovaldes3785
    @diegovaldes3785 ปีที่แล้ว +1

    is there a way that the row number continues the sequence after running the same query again?

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  ปีที่แล้ว

      Great question. It should continue generating more numbers if you added rows to the table, then executed the query again. Is that what you mean?

    • @diegovaldes3785
      @diegovaldes3785 ปีที่แล้ว

      @@seanmackenziedataengineering hmm let me give you an example: I made a query that selects data based on a search criteria and want a sequence number related to each one of the items of this data, then a process unrelated to SQL does things with that data so it does not fit with the search criteria. What I need is that, whenever new data comes in that fits the search data, the sequence number continues where it was left

  • @maheshs8069
    @maheshs8069 ปีที่แล้ว +1

    Sir, will these rownum work for table with million record

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  ปีที่แล้ว

      I don't see why not! Give it a try. It may slow down though. At a point, you may want to just add a column to that table and make it persistent (and faster to work with).

  • @anilmanuka2052
    @anilmanuka2052 2 ปีที่แล้ว +1

    How to update empty column a value in declare table

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  2 ปีที่แล้ว

      If you are creating a new table, you can use a default to fill values that are not selected. If you wanted a date for example, you could make the field:
      MyDateField datetime default GetDate()

  • @alekkermd7775
    @alekkermd7775 2 ปีที่แล้ว +1

    The background music is very distracting.

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  2 ปีที่แล้ว

      Thanks for the feedback! All my newest videos removed the intro music.

    • @USA_to_Asia_in_2024
      @USA_to_Asia_in_2024 4 หลายเดือนก่อน

      Check out the mirror and you'll see a crybaby who cries about music and should have bigger fish to fry