{"id":1830,"date":"2011-06-09T16:34:48","date_gmt":"2011-06-09T08:34:48","guid":{"rendered":"http:\/\/jason695.why3s.tw\/wordpress\/?p=1830"},"modified":"2011-12-14T14:02:20","modified_gmt":"2011-12-14T06:02:20","slug":"%e4%bd%bf%e7%94%a8-pivot-%e5%92%8c-unpivot","status":"publish","type":"post","link":"https:\/\/jason695.why3s.tw\/wordpress\/2011\/06\/09\/%e4%bd%bf%e7%94%a8-pivot-%e5%92%8c-unpivot\/","title":{"rendered":"\u4f7f\u7528 PIVOT \u548c UNPIVOT"},"content":{"rendered":"<p><a href=\"http:\/\/technet.microsoft.com\/zh-tw\/library\/ms177410.aspx\" target=\"_blank\">http:\/\/technet.microsoft.com\/zh-tw\/library\/ms177410.aspx<\/a><\/p>\n<pre lang=\"sql\">DROP TABLE #pvt\r\n\r\nCREATE TABLE #pvt (VendorID varchar(10), Emp1 int);\r\nGO\r\nINSERT INTO #pvt VALUES ('A121',4121);\r\nINSERT INTO #pvt VALUES ('A121',4345);\r\nINSERT INTO #pvt VALUES ('A121',4454);\r\nINSERT INTO #pvt VALUES ('A122',1234);\r\nINSERT INTO #pvt VALUES ('A122',1121);\r\nINSERT INTO #pvt VALUES ('A123',5232);\r\n\r\nselect * from #pvt\r\n\r\nSELECT *\r\nFROM \r\n(SELECT VendorID,Emp1\r\n\t,ROW_NUMBER() OVER(partition by VendorID order by VendorID) RID\r\nFROM #pvt) p\r\nPIVOT\r\n(\r\nMAX(Emp1)\r\nFOR RID IN --\u7528RID\u5c0d\u61c9\u8981\u585e\u5165\u7684\u6b04\u4f4d\r\n( [1], [2], [3])\r\n) AS pvt1<\/pre>\n<p>\u8f38\u51fa\u7d50\u679c:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/technet.microsoft.com\/zh-tw\/library\/ms177410.asp &hellip; <a href=\"https:\/\/jason695.why3s.tw\/wordpress\/2011\/06\/09\/%e4%bd%bf%e7%94%a8-pivot-%e5%92%8c-unpivot\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">\u4f7f\u7528 PIVOT \u548c UNPIVOT<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1830","post","type-post","status-publish","format-standard","hentry","category-5","no-featured-image"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/1830","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/comments?post=1830"}],"version-history":[{"count":0,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/1830\/revisions"}],"wp:attachment":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/media?parent=1830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/categories?post=1830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/tags?post=1830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}