{"id":1675,"date":"2011-04-06T12:07:22","date_gmt":"2011-04-06T12:07:22","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=1675"},"modified":"2011-07-07T00:39:12","modified_gmt":"2011-07-07T00:39:12","slug":"select-top%e7%9a%84%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2011\/04\/06\/select-top%e7%9a%84%e7%94%a8%e6%b3%95\/","title":{"rendered":"SELECT TOP\u7684\u7528\u6cd5"},"content":{"rendered":"<p>\u770b\u4e86\u4e0bSQL SERVER2005 \u5173\u4e8eTOP\u7684\u5b9a\u4e49\uff0c\u53d1\u73b0\u6709\u4e00\u4e9b\u7528\u6cd5\u8fd8\u6ca1\u638c\u63e1<br \/>\n1,\u53d6\u524d40% select top (40) percent from table1 &#8211;\u82e5\u8ba1\u7b97\u51fa\u7684\u884c\u6570\u662f\u5c0f\u6570\uff0c\u5219\u6700\u7ec8\u884c\u6570\u4f1a\u5411\u4e0a\u53d6\u6574<br \/>\n2,declare   @i   int<br \/>\n   set   @i=1<br \/>\n   select top @i, * from table1<br \/>\n\u5728\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u5f97\u4e0d\u5230\u6267\u884c\uff0c\u56e0\u4e3atop\u65f6\u540e\u9762\u53ea\u80fd\u662f\u5e38\u91cf\u3002 \u4e4b\u524d\u8fd9\u6837\u8ba4\u4e3a\uff0c\u5e76\u7528\u4e86set  rowcount @i\u89e3\u51b3\uff0c<br \/>\n\u4f46\u5176\u5b9e\u53ef\u7528\uff1aselect top (@i) * from table1\u6765\u89e3\u51b3<\/p>\n<p>3\uff0c\u5728UPDATE,DELETE \u4e2d\u4f7f\u7528TOP<br \/>\nUPDATE TOP (2)  frmuser<br \/>\nSET LastEditDate = GETDATE()<\/p>\n<p>DELETE TOP (2) FROM frmUser<\/p>\n<p>4,select top (@i)\u4f7f\u7528\uff1a\u5bf9\u4e8esys.objects\u6570\u636e\u5e93\uff0c\u82e5\u7c7b\u578b\u4e3as\u5219\u53d62\u6761\uff0cv 1\u6761\uff0cp,3\u6761<br \/>\nWITH lib AS(<br \/>\n    SELECT &#8216;s&#8217; TYPE ,2 showcount        &#8211;\u5c06\u89c4\u5219\u56fa\u5b9a\u5316<br \/>\n    UNION ALL<br \/>\n    SELECT &#8216;v&#8217;,1<br \/>\n    UNION ALL<br \/>\n    SELECT &#8216;p&#8217;,3<br \/>\n)<\/p>\n<p>SELECT lib.*,o.*<br \/>\nFROM lib<br \/>\nCROSS APPLY(SELECT TOP (lib.showcount) NAME,create_date<br \/>\nFROM sys.objects o<br \/>\nWHERE o.[type] = lib.type<br \/>\nORDER BY o.create_date)o<br \/>\nORDER BY lib.type,o.create_Date<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u770b\u4e86\u4e0bSQL SERVER2005 \u5173\u4e8eTOP\u7684\u5b9a\u4e49\uff0c\u53d1\u73b0\u6709\u4e00\u4e9b\u7528\u6cd5\u8fd8\u6ca1\u638c\u63e1 1,\u53d6\u524d40% select t [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-1675","post","type-post","status-publish","format-standard","hentry","category-sql-server"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/1675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=1675"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/1675\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=1675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=1675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=1675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}