{"id":76,"date":"2020-06-02T20:44:32","date_gmt":"2020-06-02T20:44:32","guid":{"rendered":"http:\/\/bahadirmeric.net\/bahadir\/?p=76"},"modified":"2020-06-02T20:44:32","modified_gmt":"2020-06-02T20:44:32","slug":"ms-sql-row_number","status":"publish","type":"post","link":"http:\/\/bahadirmeric.net\/bahadir\/2020\/06\/02\/ms-sql-row_number\/","title":{"rendered":"MS SQL Row_Number"},"content":{"rendered":"\n<p>Ms-Sql\u2019 de bir \u00e7\u0131kt\u0131 \u00fcretirken bir kolonuna bir sat\u0131r numaras\u0131 verme gere\u011fi hissedebilirsiniz, veya belli kriterlere g\u00f6re verileri s\u0131ralay\u0131p her birini sat\u0131r numaras\u0131yla belli etmek isteyebilirsiniz b\u00f6yle durumlarda ms-sql\u2019 de \u201c<strong>Row_Number<\/strong>\u201d komutu \u00e7ok i\u015finizi g\u00f6recektir.<\/p>\n\n\n\n<p>Temel bazda Row_Number a\u015fa\u011f\u0131daki gibi yaz\u0131l\u0131;<\/p>\n\n\n\n<p>\u201cROW_NUMBER ( ) &nbsp;&nbsp;&nbsp;&nbsp;OVER ( [ PARTITION BY value_expression , \u2026 [ n ] ] order_by_clause )\u201d<\/p>\n\n\n\n<p>A\u015fa\u011f\u0131daki kodu ve \u00e7\u0131kt\u0131s\u0131n\u0131 bir inceleyelim;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT ROW_NUMBER() OVER(ORDER BY SalesYTD DESC) AS 'Row',\n    FirstName, LastName, ROUND(SalesYTD,2,1)\nFROM Sales.vSalesPerson\nWHERE TerritoryName IS NOT NULL AND SalesYTD &lt;&gt; 0\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"446\" height=\"229\" src=\"http:\/\/bahadirmeric.net\/bahadir\/wp-content\/uploads\/2020\/06\/rownumber1.jpg\" alt=\"\" class=\"wp-image-78\" srcset=\"http:\/\/bahadirmeric.net\/bahadir\/wp-content\/uploads\/2020\/06\/rownumber1.jpg 446w, http:\/\/bahadirmeric.net\/bahadir\/wp-content\/uploads\/2020\/06\/rownumber1-300x154.jpg 300w, http:\/\/bahadirmeric.net\/bahadir\/wp-content\/uploads\/2020\/06\/rownumber1-150x77.jpg 150w, http:\/\/bahadirmeric.net\/bahadir\/wp-content\/uploads\/2020\/06\/rownumber1-250x128.jpg 250w\" sizes=\"auto, (max-width: 446px) 100vw, 446px\" \/><\/figure>\n\n\n\n<p>Yukar\u0131daki \u00e7\u0131kt\u0131 incelendi\u011finde sorguda yer alan \u201c<strong>SalesYTD<\/strong>\u201d alan\u0131na g\u00f6re bir dizilim yap\u0131lm\u0131\u015f ve s\u0131ralama yap\u0131lm\u0131\u015ft\u0131r. \u201c<strong>Row_Number<\/strong>\u201d \u0131n bir kullan\u0131m \u015fekli daha mevcuttur. Bunu a\u00e7\u0131klamas\u0131 biraz karma\u015f\u0131k ama kod ve \u00e7\u0131kt\u0131s\u0131n\u0131 inceleyerek&nbsp; daha rahat anlayabilece\u011fimizi d\u00fc\u015f\u00fcn\u00fcyorum.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT FirstName, LastName, TerritoryName, ROUND(SalesYTD,2,1),\nROW_NUMBER() OVER(PARTITION BY TerritoryName ORDER BY SalesYTD DESC) AS 'Row'\nFROM Sales.vSalesPerson\nWHERE TerritoryName IS NOT NULL AND SalesYTD &lt;&gt; 0\nORDER BY TerritoryName\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"542\" height=\"363\" src=\"http:\/\/bahadirmeric.net\/bahadir\/wp-content\/uploads\/2020\/06\/rownumber2.jpg\" alt=\"\" class=\"wp-image-80\" srcset=\"http:\/\/bahadirmeric.net\/bahadir\/wp-content\/uploads\/2020\/06\/rownumber2.jpg 542w, http:\/\/bahadirmeric.net\/bahadir\/wp-content\/uploads\/2020\/06\/rownumber2-300x201.jpg 300w, http:\/\/bahadirmeric.net\/bahadir\/wp-content\/uploads\/2020\/06\/rownumber2-150x100.jpg 150w, http:\/\/bahadirmeric.net\/bahadir\/wp-content\/uploads\/2020\/06\/rownumber2-224x150.jpg 224w\" sizes=\"auto, (max-width: 542px) 100vw, 542px\" \/><\/figure>\n\n\n\n<p>\u00c7\u0131kt\u0131y\u0131 inceledi\u011finizde \u201c<strong>SalesYTD<\/strong>\u201d alan\u0131na g\u00f6re bir s\u0131ralama yap\u0131l\u0131rken \u201c<strong>TerritoryName<\/strong>\u201d alan\u0131na g\u00f6rede bir guruplama yap\u0131lmaya \u00e7al\u0131\u015f\u0131lm\u0131\u015f ve \u201c<strong>Row<\/strong>\u201d alan\u0131ndaki veri bu gruplamaya g\u00f6re verilmi\u015ftir.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ms-Sql\u2019 de bir \u00e7\u0131kt\u0131 \u00fcretirken bir kolonuna bir sat\u0131r numaras\u0131 verme gere\u011fi hissedebilirsiniz, veya belli kriterlere g\u00f6re verileri s\u0131ralay\u0131p her birini sat\u0131r numaras\u0131yla belli etmek isteyebilirsiniz b\u00f6yle durumlarda ms-sql\u2019 de \u201cRow_Number\u201d komutu \u00e7ok i\u015finizi g\u00f6recektir. Temel bazda Row_Number a\u015fa\u011f\u0131daki gibi yaz\u0131l\u0131; \u201cROW_NUMBER ( ) &nbsp;&nbsp;&nbsp;&nbsp;OVER ( [ PARTITION BY value_expression&#8230; <a class=\"continue-reading-link\" href=\"http:\/\/bahadirmeric.net\/bahadir\/2020\/06\/02\/ms-sql-row_number\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":10,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[8,2],"class_list":["post-76","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-ms-sql","tag-sql"],"_links":{"self":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":3,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":81,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/posts\/76\/revisions\/81"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/media\/10"}],"wp:attachment":[{"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bahadirmeric.net\/bahadir\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}