{"id":116,"date":"2025-07-16T10:42:49","date_gmt":"2025-07-16T02:42:49","guid":{"rendered":"https:\/\/www.hgfwq.com\/blog\/?p=116"},"modified":"2025-07-16T10:42:49","modified_gmt":"2025-07-16T02:42:49","slug":"sql-round-%e7%94%a8%e6%b3%95%e4%b8%8e%e5%9b%9b%e8%88%8d%e4%ba%94%e5%85%a5%e5%a4%9a%e5%b0%91%e4%bd%8d%e6%95%b0%e7%9a%84%e5%ba%94%e7%94%a8%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/www.hgfwq.com\/blog\/116.html","title":{"rendered":"SQL ROUND \u7528\u6cd5\u4e0e\u56db\u820d\u4e94\u5165\u591a\u5c11\u4f4d\u6570\u7684\u5e94\u7528\u8bf4\u660e"},"content":{"rendered":"<p><h3>\u5168\u7bc7\u7cbe\u534e<\/h3>\n<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.hgfwq.com\/blog\/wp-content\/uploads\/2025\/07\/AZWmi6o.jpg\" alt=\"SQL ROUND \u7528\u6cd5\u4e0e\u56db\u820d\u4e94\u5165\u591a\u5c11\u4f4d\u6570\u7684\u5e94\u7528\u8bf4\u660e\" title=\"SQL ROUND \u7528\u6cd5\u4e0e\u56db\u820d\u4e94\u5165\u591a\u5c11\u4f4d\u6570\u7684\u5e94\u7528\u8bf4\u660e\"><\/p>\n<p><p>SQL\u4e2d\u7684ROUND\u51fd\u6570\u7528\u4e8e\u5c06\u6570\u503c\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u7684\u4f4d\u6570\uff0c\u662f\u6570\u636e\u5e93\u64cd\u4f5c\u4e2d\u5e38\u7528\u7684\u51fd\u6570\u4e4b\u4e00\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecdROUND\u51fd\u6570\u7684\u7528\u6cd5\uff0c\u5305\u62ec\u5176\u53c2\u6570\u8bbe\u7f6e\u3001\u8fd4\u56de\u503c\u4ee5\u53ca\u5728\u5b9e\u9645\u6570\u636e\u5e93\u64cd\u4f5c\u4e2d\u7684\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h3>ROUND\u51fd\u6570\u7b80\u4ecb<\/h3>\n<\/p>\n<p><p>ROUND\u51fd\u6570\u662fSQL\u4e2d\u7528\u4e8e\u6570\u503c\u56db\u820d\u4e94\u5165\u7684\u6807\u51c6\u51fd\u6570\u3002\u5b83\u53ef\u4ee5\u5c06\u6570\u503c\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u7684\u6574\u6570\u4f4d\u6570\u6216\u5c0f\u6570\u4f4d\u6570\u3002ROUND\u51fd\u6570\u7684\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><p><code>ROUND(number, digits)<\/code><\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>number<\/code>\u662f\u8981\u8fdb\u884c\u56db\u820d\u4e94\u5165\u7684\u6570\u503c\uff0c<code>digits<\/code>\u662f\u8981\u4fdd\u7559\u7684\u5c0f\u6570\u4f4d\u6570\u3002\u5982\u679c<code>digits<\/code>\u4e3a\u8d1f\u6570\uff0c\u5219\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u5de6\u8fb9\u7684\u4f4d\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u53c2\u6570\u8bbe\u7f6e\u4e0e\u8fd4\u56de\u503c<\/h3>\n<\/p>\n<p>\n<h3>\u53c2\u6570\u8bbe\u7f6e<\/h3>\n<\/p>\n<p><p>1. <code>number<\/code>\uff1a\u53ef\u4ee5\u662f\u6574\u6570\u6216\u6d6e\u70b9\u6570\u3002<\/p>\n<\/p>\n<p><p>2. <code>digits<\/code>\uff1a\u6307\u5b9a\u4fdd\u7559\u7684\u5c0f\u6570\u4f4d\u6570\uff0c\u53ef\u4ee5\u662f\u6574\u6570\u6216\u6d6e\u70b9\u6570\u3002\u5982\u679c\u7701\u7565\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u5373\u56db\u820d\u4e94\u5165\u5230\u6574\u6570\u3002<\/p>\n<\/p>\n<p>\n<h3>\u8fd4\u56de\u503c<\/h3>\n<\/p>\n<p><p>ROUND\u51fd\u6570\u8fd4\u56de\u56db\u820d\u4e94\u5165\u540e\u7684\u6570\u503c\u3002\u5982\u679c<code>digits<\/code>\u4e3a\u8d1f\u6570\uff0c\u5219\u8fd4\u56de\u5c0f\u6570\u70b9\u5de6\u8fb9\u7684\u6574\u6570\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><p><code>ROUND(123.456, 2)<\/code> \u8fd4\u56de 123.46<\/p>\n<\/p>\n<p><p><code>ROUND(123.456, -1)<\/code> \u8fd4\u56de 100<\/p>\n<\/p>\n<p><h3>\u5b9e\u9645\u5e94\u7528\u6848\u4f8b<\/h3>\n<\/p>\n<p>\n<h3>\u6848\u4f8b\u4e00\uff1a\u56db\u820d\u4e94\u5165\u5230\u6574\u6570<\/h3>\n<\/p>\n<p><p>\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a<code>sales<\/code>\u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u540d\u4e3a<code>revenue<\/code>\u7684\u5217\uff0c\u5b58\u50a8\u9500\u552e\u91d1\u989d\u3002\u73b0\u5728\u9700\u8981\u67e5\u8be2\u6bcf\u4e2a\u9500\u552e\u4eba\u5458\u7684\u9500\u552e\u603b\u989d\uff0c\u5e76\u56db\u820d\u4e94\u5165\u5230\u6700\u63a5\u8fd1\u7684\u6574\u6570\u3002<\/p>\n<\/p>\n<p><p>SQL\u8bed\u53e5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><p><code>SELECT employee_id, ROUND(SUM(revenue), 0) AS total_revenue FROM sales GROUP BY employee_id;<\/code><\/p>\n<\/p>\n<p>\n<h3>\u6848\u4f8b\u4e8c\uff1a\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d<\/h3>\n<\/p>\n<p><p>\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a<code>products<\/code>\u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u540d\u4e3a<code>price<\/code>\u7684\u5217\uff0c\u5b58\u50a8\u4ea7\u54c1\u4ef7\u683c\u3002\u73b0\u5728\u9700\u8981\u67e5\u8be2\u6bcf\u4e2a\u4ea7\u54c1\u7684\u4ef7\u683c\uff0c\u5e76\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d\u3002<\/p>\n<\/p>\n<p><p>SQL\u8bed\u53e5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><p><code>SELECT product_id, ROUND(price, 2) AS rounded_price FROM products;<\/code><\/p>\n<\/p>\n<p><h3>\u5e38\u89c1\u95ee\u9898\u89e3\u7b54<\/h3>\n<\/p>\n<p><p><b>\u95ee\uff1a<\/b>ROUND\u51fd\u6570\u53ef\u4ee5\u5904\u7406\u8d1f\u6570\u5417\uff1f<\/p>\n<\/p>\n<p><p>\u7b54\uff1a\u662f\u7684\uff0cROUND\u51fd\u6570\u53ef\u4ee5\u5904\u7406\u8d1f\u6570\u3002\u4f8b\u5982\uff0c<code>ROUND(-123.456, 2)<\/code> \u5c06\u8fd4\u56de -123.46\u3002<\/p>\n<\/p>\n<p><p><b>\u95ee\uff1a<\/b>ROUND\u51fd\u6570\u548cCEILING\u51fd\u6570\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/p>\n<\/p>\n<p><p>\u7b54\uff1aROUND\u51fd\u6570\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u7684\u5c0f\u6570\u4f4d\u6570\uff0c\u800cCEILING\u51fd\u6570\u5411\u4e0a\u53d6\u6574\u5230\u6700\u63a5\u8fd1\u7684\u6574\u6570\u3002\u4f8b\u5982\uff0c<code>CEILING(-123.456)<\/code> \u5c06\u8fd4\u56de -123\uff0c\u800c<code>ROUND(-123.456, 0)<\/code> \u5c06\u8fd4\u56de -124\u3002<\/p>\n<\/p>\n<p><p><b>\u95ee\uff1a<\/b>ROUND\u51fd\u6570\u53ef\u4ee5\u5904\u7406\u975e\u5e38\u5927\u7684\u6570\u503c\u5417\uff1f<\/p>\n<\/p>\n<p><p>\u7b54\uff1a\u662f\u7684\uff0cROUND\u51fd\u6570\u53ef\u4ee5\u5904\u7406\u975e\u5e38\u5927\u7684\u6570\u503c\uff0c\u4f46\u5177\u4f53\u53d6\u51b3\u4e8e\u6570\u636e\u5e93\u7cfb\u7edf\u652f\u6301\u7684\u6570\u503c\u8303\u56f4\u3002\u5728\u67d0\u4e9b\u6570\u636e\u5e93\u4e2d\uff0c\u5982\u679c\u6570\u503c\u8fc7\u5927\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u6ea2\u51fa\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>ROUND\u51fd\u6570\u662fSQL\u4e2d\u5904\u7406\u6570\u503c\u56db\u820d\u4e94\u5165\u7684\u91cd\u8981\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u7cbe\u786e\u5730\u63a7\u5236\u6570\u636e\u7684\u663e\u793a\u548c\u8ba1\u7b97\u3002\u901a\u8fc7\u7406\u89e3ROUND\u51fd\u6570\u7684\u7528\u6cd5\u548c\u53c2\u6570\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u5728\u6570\u636e\u5e93\u64cd\u4f5c\u4e2d\u5e94\u7528\u8fd9\u4e00\u51fd\u6570\uff0c\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7684\u51c6\u786e\u6027\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5168\u7bc7\u7cbe\u534e SQL\u4e2d\u7684ROUND\u51fd\u6570\u7528\u4e8e\u5c06\u6570\u503c\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u7684\u4f4d\u6570\uff0c\u662f\u6570\u636e\u5e93\u64cd\u4f5c\u4e2d\u5e38\u7528\u7684\u51fd\u6570\u4e4b\u4e00\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecdROUND\u51fd\u6570\u7684\u7528\u6cd5\uff0c\u5305\u62ec\u5176\u53c2\u6570\u8bbe\u7f6e\u3001\u8fd4\u56de\u503c\u4ee5\u53ca\u5728\u5b9e\u9645\u6570\u636e\u5e93\u64cd\u4f5c\u4e2d\u7684\u5e94\u7528\u3002 ROUND\u51fd\u6570\u7b80\u4ecb ROUND\u51fd\u6570\u662fSQL\u4e2d\u7528\u4e8e\u6570\u503c\u56db&#8230;<\/p>\n","protected":false},"author":1,"featured_media":117,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[68,70,69],"topic":[],"class_list":["post-116","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-haiwai","tag-round","tag-70","tag-69"],"_links":{"self":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":1,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions\/119"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/media\/117"}],"wp:attachment":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/tags?post=116"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/topic?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}