{"id":3171,"date":"2019-11-11T22:31:56","date_gmt":"2019-11-11T21:31:56","guid":{"rendered":"http:\/\/van-maanen.com\/?p=3171"},"modified":"2019-11-11T22:31:56","modified_gmt":"2019-11-11T21:31:56","slug":"oracle-provide-a-rank","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=3171","title":{"rendered":"Oracle &#8211; provide a rank"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Oracl has a nice feature to add a rank to a row. Let us assume you have a table with 4 values: some rows have an A, others have a B, others have a C and some are D. Oracle  is able to provide a rank to this series by providing a 1 to A, 2 to B, 3 to C and 4 to D.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This could be used (for example) is we have prices that we would like to order: the lowest price a 1, second a 2 etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The code is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> CREATE TABLE rank_demo ( col VARCHAR(10) NOT NULL); <\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">INSERT ALL \nINTO rank_demo(col) VALUES('A')\nINTO rank_demo(col) VALUES('A')\nINTO rank_demo(col) VALUES('B')\nINTO rank_demo(col) VALUES('C')\nINTO rank_demo(col) VALUES('C')\nINTO rank_demo(col) VALUES('C')\nINTO rank_demo(col) VALUES('D')\nSELECT 1 FROM dual; \n\nSELECT  col,  dense_RANK() OVER (ORDER BY col) my_rank\nFROM  rank_demo; <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Which provides:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/van-maanen.com\/wp-content\/uploads\/2019\/11\/Capture-1-1.png\" alt=\"\" class=\"wp-image-3172\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Oracl has a nice feature to add a rank to a row. Let us assume you have a table with 4 values: some rows have an A, others have a B, others have a C and some are D. Oracle is able to provide a rank to this series by providing a 1 to A, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3171","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3171"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3171\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3171"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}