{"id":2181,"date":"2012-03-28T23:04:27","date_gmt":"2012-03-28T15:04:27","guid":{"rendered":"http:\/\/jason695.why3s.tw\/wordpress\/?p=2181"},"modified":"2012-03-29T00:31:05","modified_gmt":"2012-03-28T16:31:05","slug":"%e8%80%83%e9%a1%8c","status":"publish","type":"post","link":"https:\/\/jason695.why3s.tw\/wordpress\/2012\/03\/28\/%e8%80%83%e9%a1%8c\/","title":{"rendered":"\u8003\u984c"},"content":{"rendered":"<p>\u554f\u984c\uff1a<br \/>\n\u53f0\u5317\u5e02\u67d0\u570b\u5c0f\u56db\u5e74\u7d1a\u6708\u8003\u984c\u76ee<\/p>\n<pre>  A B C D E\r\nX   \u00a0  \u00a0    \u00a0 A\r\n--------------\r\nE E E E E E<\/pre>\n<p>\u8acb\u554fABCDE\u5404\u4ee3\u8868\u90a3\u4e00\u500b\u963f\u62c9\u4f2f\u6578\u5b57&#8230;.(\u689d\u4ef6:\u6578\u5b57\u4e0d\u80fd\u91cd\u8986)<\/p>\n<pre lang=\"SQL\">\r\nIF OBJECT_ID('tempdb..#TMP') is not null\r\n\tdrop table #TMP\r\n\r\nselect '0' val \r\ninto #TMP --\u7522\u751f0~9\u7684\u7d50\u679c\u96c6\r\nunion \r\nselect '1'\r\nunion \r\nselect '2'\r\nunion \r\nselect '3'\r\nunion \r\nselect '4'\r\nunion \r\nselect '5'\r\nunion \r\nselect '6'\r\nunion \r\nselect '7'\r\nunion \r\nselect '8'\r\nunion \r\nselect '9'\r\n\r\nDeclare @result BIT = 0 --1:true \/ 0:false\r\nDeclare @CNT INT = 0\r\n\r\nIF OBJECT_ID('tempdb..#TMP_3') is not null\r\n\tbegin\r\n\t\tDROP TABLE #TMP_3\r\n\t\t\r\n\t\tselect '0' A\r\n\t\t\t,'1' B\r\n\t\t\t,'2' C\r\n\t\t\t,'3' D \r\n\t\t\t,'4' E \r\n\t\t\t,'01234' X\r\n\t\tinto #TMP_3\t --\u6240\u6709\u7b26\u5408\u7684\u7d50\u679c\t\t\r\n\tend\r\n\t\r\n\r\nwhile @result <> 1\r\n\tBEGIN\r\n\t\tIF OBJECT_ID('tempdb..#TMP_1') is not null\r\n\t\t\tDROP TABLE #TMP_1\t\t\t\t\t\r\n\t\t\r\n\t\tSELECT top 5 val \r\n\t\t\t, IDENTITY(INT,1,1) RID\r\n\t\tinto #TMP_1 --\u4e82\u6578\u53d6\u5f975\u7b46\r\n\t\tFROM #TMP\r\n\t\tORDER BY NEWID()\t\t\t\r\n\t\t\r\n\t\t\r\n\t\tIF OBJECT_ID('tempdb..#TMP_2') is not null\r\n\t\t\tDROP TABLE #TMP_2\r\n\t\t\t\r\n\t\tselect [1] as '1'\r\n\t\t\t, [2] as '2'\r\n\t\t\t, [3] as '3'\r\n\t\t\t, [4] as '4'\r\n\t\t\t, [5] as '5'\t\t\t\t\t\r\n\t\tinto #TMP_2 --\u6539\u70ba\u6a6b\u5f0f\r\n\t\tfrom\r\n\t\t\t(select val,rid from #TMP_1) as p\r\n\t\tpivot\r\n\t\t\t(\r\n\t\t\tmax(val)\r\n\t\t\tfor rid in ([1], [2], [3], [4], [5]) \r\n\t\t\t) as pt\r\n\t\t\r\n\t\t--select * from #TMP_3 order by X\r\n\t\t\r\n\t\tinsert into #TMP_3\r\n\t\tselect *, [1]+[2]+[3]+[4]+[5]\r\n\t\tfrom #TMP_2 T\r\n\t\twhere T.[1]+T.[2]+T.[3]+T.[4]+T.[5] not in (select X from #TMP_3)\r\n\t\t\t\r\n\t\tif @@ROWCOUNT = 0 \r\n\t\tbegin \r\n\t\t\tset @CNT = @CNT+1\r\n\t\tend \r\n\t\t\r\n\t\tif @CNT>50 --\u82e5\u627e\u4e0d\u523050\u6b21\u5247EXIT\r\n\t\tbegin\r\n\t\t\tset @result = 1 \r\n\t\tend\r\n\t\t\r\n\tEND\r\n\t\r\nselect *\t\t\t\t\t\t\t\t\t\r\nfrom #TMP_3 \r\nwhere [A]*(([A]*10000) + ([B]*1000) + ([C]*100) + ([D]*10) + [E]) = [E]*111111 \r\n\r\n--\u8f38\u51fa\u7d50\u679c\r\nselect 7*((7*10000) + (9*1000) + (3*100) + (6*10) + 5) <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u554f\u984c\uff1a \u53f0\u5317\u5e02\u67d0\u570b\u5c0f\u56db\u5e74\u7d1a\u6708\u8003\u984c\u76ee A B C D E X \u00a0 \u00a0 \u00a0 A &#8212;&#8212;&#8212;&#8212;&#8211; E  &hellip; <a href=\"https:\/\/jason695.why3s.tw\/wordpress\/2012\/03\/28\/%e8%80%83%e9%a1%8c\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">\u8003\u984c<\/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":[47],"tags":[],"class_list":["post-2181","post","type-post","status-publish","format-standard","hentry","category-sql-server","no-featured-image"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/2181","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=2181"}],"version-history":[{"count":0,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/2181\/revisions"}],"wp:attachment":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/media?parent=2181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/categories?post=2181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/tags?post=2181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}