{"id":66225,"date":"2024-10-14T15:37:17","date_gmt":"2024-10-14T07:37:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/66225\/"},"modified":"2024-10-14T15:37:17","modified_gmt":"2024-10-14T07:37:17","slug":"mssql%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%adabs%e6%ad%a3%e5%80%bc%e5%87%bd%e6%95%b8%e7%9a%84%e6%87%89%e7%94%a8%ef%bc%88mssql%e6%b1%82%e6%ad%a3%e5%80%bc%e5%87%bd%e6%95%b8%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/66225\/","title":{"rendered":"MSSQL\u6578\u64da\u5eab\u4e2dABS\u6b63\u503c\u51fd\u6578\u7684\u61c9\u7528\uff08mssql\u6c42\u6b63\u503c\u51fd\u6578\uff09"},"content":{"rendered":"<h1 id=\"mssql%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b8%adabs%e6%ad%a3%e5%80%bc%e5%87%bd%e6%95%b8%e7%9a%84%e6%87%89%e7%94%a8%ef%bc%88mssql%e6%b1%82%e6%ad%a3%e5%80%bc%e5%87%bd%e6%95%b8%ef%bc%89-RMMDfblEjW\">MSSQL\u6578\u64da\u5eab\u4e2dABS\u6b63\u503c\u51fd\u6578\u7684\u61c9\u7528\uff08mssql\u6c42\u6b63\u503c\u51fd\u6578\uff09<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u6578\u64da\u7684\u8655\u7406\u548c\u5206\u6790\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002Microsoft SQL Server\uff08MSSQL\uff09\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u5167\u5efa\u51fd\u6578\u4f86\u5e6b\u52a9\u7528\u6236\u9032\u884c\u6578\u64da\u64cd\u4f5c\u3002\u5176\u4e2d\uff0cABS\u51fd\u6578\u662f\u4e00\u500b\u5e38\u7528\u7684\u6578\u5b78\u51fd\u6578\uff0c\u7528\u65bc\u8fd4\u56de\u6578\u5b57\u7684\u7d55\u5c0d\u503c\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eABS\u51fd\u6578\u7684\u61c9\u7528\u53ca\u5176\u5728MSSQL\u4e2d\u7684\u5be6\u73fe\u65b9\u5f0f\u3002<\/p>\n<h2 id=\"abs%e5%87%bd%e6%95%b8%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-RMMDfblEjW\">ABS\u51fd\u6578\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>ABS\u51fd\u6578\u7684\u5168\u540d\u662f\u201cAbsolute Value Function\u201d\uff0c\u5176\u4e3b\u8981\u529f\u80fd\u662f\u5c07\u4efb\u4f55\u6578\u5b57\u8f49\u63db\u70ba\u5176\u6b63\u503c\u3002\u9019\u610f\u5473\u8457\u7121\u8ad6\u8f38\u5165\u7684\u6578\u5b57\u662f\u6b63\u6578\u3001\u8ca0\u6578\u9084\u662f\u96f6\uff0cABS\u51fd\u6578\u90fd\u6703\u8fd4\u56de\u4e00\u500b\u975e\u8ca0\u7684\u6578\u5b57\u3002\u5176\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>ABS ( numeric_expression )<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c<code>numeric_expression<\/code>\u53ef\u4ee5\u662f\u4efb\u4f55\u6578\u5b57\u985e\u578b\u7684\u8868\u9054\u5f0f\uff0c\u5305\u62ec\u6574\u6578\u3001\u6d6e\u9ede\u6578\u7b49\u3002<\/p>\n<h2 id=\"abs%e5%87%bd%e6%95%b8%e7%9a%84%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af-RMMDfblEjW\">ABS\u51fd\u6578\u7684\u61c9\u7528\u5834\u666f<\/h2>\n<p>ABS\u51fd\u6578\u5728\u6578\u64da\u5206\u6790\u548c\u5831\u544a\u4e2d\u6709\u591a\u7a2e\u61c9\u7528\u5834\u666f\uff0c\u4ee5\u4e0b\u662f\u5e7e\u500b\u5e38\u898b\u7684\u4f8b\u5b50\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u6e05\u7406\uff1a<\/strong>\u5728\u6578\u64da\u6e05\u7406\u904e\u7a0b\u4e2d\uff0c\u53ef\u80fd\u6703\u9047\u5230\u8ca0\u503c\u6578\u64da\u3002\u4f7f\u7528ABS\u51fd\u6578\u53ef\u4ee5\u8f15\u9b06\u5c07\u9019\u4e9b\u8ca0\u503c\u8f49\u63db\u70ba\u6b63\u503c\uff0c\u5f9e\u800c\u63d0\u9ad8\u6578\u64da\u7684\u53ef\u7528\u6027\u3002<\/li>\n<li><strong>\u8ca1\u52d9\u5831\u8868\uff1a<\/strong>\u5728\u8ca1\u52d9\u5831\u8868\u4e2d\uff0c\u7d93\u5e38\u9700\u8981\u8a08\u7b97\u640d\u5931\u7684\u7d55\u5c0d\u503c\u3002\u4f7f\u7528ABS\u51fd\u6578\u53ef\u4ee5\u5feb\u901f\u7372\u5f97\u640d\u5931\u7684\u6b63\u503c\uff0c\u4fbf\u65bc\u5f8c\u7e8c\u7684\u5206\u6790\u548c\u5831\u544a\u3002<\/li>\n<li><strong>\u7d71\u8a08\u5206\u6790\uff1a<\/strong>\u5728\u9032\u884c\u7d71\u8a08\u5206\u6790\u6642\uff0c\u53ef\u80fd\u9700\u8981\u8a08\u7b97\u6578\u64da\u7684\u504f\u5dee\u3002\u4f7f\u7528ABS\u51fd\u6578\u53ef\u4ee5\u5e6b\u52a9\u8a08\u7b97\u504f\u5dee\u7684\u7d55\u5c0d\u503c\uff0c\u5f9e\u800c\u66f4\u597d\u5730\u7406\u89e3\u6578\u64da\u7684\u5206\u4f48\u60c5\u6cc1\u3002<\/li>\n<\/ul>\n<h2 id=\"abs%e5%87%bd%e6%95%b8%e7%9a%84%e5%af%a6%e4%be%8b-RMMDfblEjW\">ABS\u51fd\u6578\u7684\u5be6\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528ABS\u51fd\u6578\u7684\u7c21\u55ae\u793a\u4f8b\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u540d\u70ba<code>Sales<\/code>\u7684\u8868\u683c\uff0c\u5176\u4e2d\u5305\u542b\u92b7\u552e\u91d1\u984d\u7684\u6578\u64da\uff1a<\/p>\n<pre><code>SELECT \n    SaleID, \n    SaleAmount, \n    ABS(SaleAmount) AS PositiveSaleAmount\nFROM \n    Sales;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u67e5\u8a62\u4e2d\uff0c\u6211\u5011\u9078\u64c7\u4e86\u92b7\u552eID\u548c\u92b7\u552e\u91d1\u984d\uff0c\u4e26\u4f7f\u7528ABS\u51fd\u6578\u8a08\u7b97\u6bcf\u7b46\u92b7\u552e\u91d1\u984d\u7684\u6b63\u503c\u3002\u9019\u6a23\u53ef\u4ee5\u5e6b\u52a9\u6211\u5011\u66f4\u6e05\u6670\u5730\u4e86\u89e3\u6bcf\u7b46\u4ea4\u6613\u7684\u5f71\u97ff\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-RMMDfblEjW\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528ABS\u51fd\u6578\u6642\uff0c\u6709\u5e7e\u9ede\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>ABS\u51fd\u6578\u50c5\u9069\u7528\u65bc\u6578\u5b57\u985e\u578b\u7684\u6578\u64da\uff0c\u5c0d\u65bc\u5176\u4ed6\u985e\u578b\u7684\u6578\u64da\uff08\u5982\u5b57\u7b26\u4e32\uff09\u5c07\u6703\u5831\u932f\u3002<\/li>\n<li>\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\uff0c\u4f7f\u7528ABS\u51fd\u6578\u53ef\u80fd\u6703\u5f71\u97ff\u67e5\u8a62\u6027\u80fd\uff0c\u56e0\u6b64\u5728\u8a2d\u8a08\u6578\u64da\u5eab\u6642\u61c9\u8003\u616e\u5230\u9019\u4e00\u9ede\u3002<\/li>\n<li>\u5728\u9032\u884c\u6578\u64da\u5206\u6790\u6642\uff0c\u61c9\u6839\u64da\u5177\u9ad4\u9700\u6c42\u9078\u64c7\u662f\u5426\u4f7f\u7528ABS\u51fd\u6578\uff0c\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6578\u64da\u8f49\u63db\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-RMMDfblEjW\">\u7e3d\u7d50<\/h2>\n<p>ABS\u51fd\u6578\u5728MSSQL\u4e2d\u662f\u4e00\u500b\u975e\u5e38\u5be6\u7528\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u7528\u6236\u8f15\u9b06\u7372\u53d6\u6578\u5b57\u7684\u6b63\u503c\u3002\u7121\u8ad6\u662f\u5728\u6578\u64da\u6e05\u7406\u3001\u8ca1\u52d9\u5831\u8868\u9084\u662f\u7d71\u8a08\u5206\u6790\u4e2d\uff0cABS\u51fd\u6578\u90fd\u80fd\u767c\u63ee\u91cd\u8981\u4f5c\u7528\u3002\u4e86\u89e3\u548c\u638c\u63e1\u9019\u4e00\u51fd\u6578\u7684\u4f7f\u7528\uff0c\u5c07\u6709\u52a9\u65bc\u63d0\u9ad8\u6578\u64da\u8655\u7406\u7684\u6548\u7387\u548c\u6e96\u78ba\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u652f\u6301\u60a8\u7684MSSQL\u6578\u64da\u5eab\u9700\u6c42\u3002\u7121\u8ad6\u662f\u6578\u64da\u5b58\u5132\u9084\u662f\u8655\u7406\uff0c\u9078\u64c7\u5408\u9069\u7684\u670d\u52d9\u5668\u90fd\u80fd\u70ba\u60a8\u7684\u696d\u52d9\u5e36\u4f86\u66f4\u5927\u7684\u4fbf\u5229\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22MSSQL\u6578\u64da\u5eab\u4e2dABS\u6b63\u503c\u51fd\u6578\u7684\u61c9\u7528\uff0c\u4e86\u89e3\u5982\u4f55\u6709\u6548\u6c42\u53d6\u6578\u64da\u7684\u6b63\u503c\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6548\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-66225","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/66225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=66225"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/66225\/revisions"}],"predecessor-version":[{"id":66226,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/66225\/revisions\/66226"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=66225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=66225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=66225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}