{"id":6687,"date":"2016-01-18T22:05:23","date_gmt":"2016-01-18T14:05:23","guid":{"rendered":"http:\/\/onthe8spot.com\/?p=6687"},"modified":"2016-01-18T22:05:23","modified_gmt":"2016-01-18T14:05:23","slug":"impress-your-coworkers-by-using-sql-unpivot","status":"publish","type":"post","link":"http:\/\/onthe8spot.com\/index.php\/2016\/01\/18\/impress-your-coworkers-by-using-sql-unpivot\/","title":{"rendered":"Impress Your Coworkers by Using SQL UNPIVOT!"},"content":{"rendered":"<p>This is a nice guide on Pivot and UnPivot usage for real problems:<\/p>\n<blockquote><p>&nbsp;<br \/>\nI\u2019ve recently encountered a very interesting <a href=\"http:\/\/stackoverflow.com\/q\/34618936\/521799\">question on Stack Overflow by an unnamed user<\/a>. The question was about generating a table of the following form in Oracle, using a table valued function:<\/p>\n<pre>Description   COUNT\n-------------------\nTEST1         10\nTEST2         15\nTEST3         25\nTEST4         50\n<\/pre>\n<p>The logic that should be implemented for the COUNT column is the following:<\/p>\n<ul>\n<li>TEST1: count of employees whose sal &lt; 10000<\/li>\n<li>TEST2: count of employees whose dept &gt; 10<\/li>\n<li>TEST3: count of employees whose hiredate &gt; (SYSDATE-60)<\/li>\n<li>TEST4: count of employees whose grade = 1<\/li>\n<\/ul>\n<p>Challenge accepted!<br \/>\n&nbsp;<br \/>\nSource: <em><a href=\"http:\/\/blog.jooq.org\/2016\/01\/18\/impress-your-coworkers-by-using-sql-unpivot\/\">Impress Your Coworkers by Using SQL UNPIVOT!<\/a><\/em><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>This is a nice guide on Pivot and UnPivot usage for real problems: &nbsp; I\u2019ve recently encountered a very interesting question on Stack Overflow by an unnamed user. The question was about generating a table of the following form in Oracle, using a table valued function: Description COUNT &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- TEST1 10 TEST2 15 TEST3 25 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/onthe8spot.com\/index.php\/2016\/01\/18\/impress-your-coworkers-by-using-sql-unpivot\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Impress Your Coworkers by Using SQL UNPIVOT!&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[79],"tags":[],"class_list":["post-6687","post","type-post","status-publish","format-standard","hentry","category-reposts"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/posts\/6687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/comments?post=6687"}],"version-history":[{"count":0,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/posts\/6687\/revisions"}],"wp:attachment":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/media?parent=6687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/categories?post=6687"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/tags?post=6687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}