{"id":7878,"date":"2024-11-14T09:58:40","date_gmt":"2024-11-14T01:58:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7878\/"},"modified":"2024-11-14T09:58:40","modified_gmt":"2024-11-14T01:58:40","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8mysql%e6%8c%89%e6%af%8f5%e5%88%86%e9%92%9f%e9%97%b4%e9%9a%94%e6%b1%87%e6%80%bb%e4%b8%80%e5%a4%a9%e7%9a%84%e6%95%b0%e6%8d%ae%e9%87%8f%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7878\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528MySQL\u6309\u6bcf5\u5206\u949f\u95f4\u9694\u6c47\u603b\u4e00\u5929\u7684\u6570\u636e\u91cf\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173131020423552.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528MySQL\u6309\u6bcf5\u5206\u949f\u95f4\u9694\u6c47\u603b\u4e00\u5929\u7684\u6570\u636e\u91cf\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528MySQL\u6309\u6bcf5\u5206\u949f\u95f4\u9694\u6c47\u603b\u4e00\u5929\u7684\u6570\u636e\u91cf\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u6309\u6bcf 5 \u5206\u949f\u95f4\u9694\u6c47\u603b\u4e00\u5929\u7684\u6570\u636e\u91cf<\/strong><\/p>\n<p>\u4e3a\u4e86\u6309\u6bcf 5 \u5206\u949f\u95f4\u9694\u6c47\u603b\u4e00\u5929\u7684\u6570\u636e\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u65f6\u95f4\u95f4\u9694\u8868<\/strong><\/li>\n<\/ol>\n<pre>create table time_intervals (\n  grouped_time time default null\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u63d2\u5165\u65f6\u95f4\u95f4\u9694\u6570\u636e<\/strong><\/li>\n<\/ol>\n<pre>delimiter \/\/\ncreate procedure inserttimeintervals()\nbegin\n    declare currenttime time default '00:00:00';\n    declare endtime time default '23:55:00';\n    truncate table time_intervals;\n    while currenttime &lt;= endtime do\n        insert into time_intervals (grouped_time) values (currenttime);\n        set currenttime = addtime(currenttime, '00:05:00');\n    end while;\nend \/\/\ndelimiter ;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u6309\u6bcf 5 \u5206\u949f\u67e5\u8be2\u771f\u5b9e\u6570\u636e<\/strong><\/li>\n<\/ol>\n<pre>select \n    date_format(create_time, '%y-%m-%d %h:%i') - interval (minute(create_time) mod 5) minute as grouped_time,\n    count(*) as couns\nfrom \n    interface_access_frequency \nwhere  \n      date(create_time) = '2024-04-27'\ngroup by \n    grouped_time;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u4f7f\u7528 union \u94fe\u63a5\u8865\u96f6\u6570\u636e<\/strong><\/li>\n<\/ol>\n<pre>(select \n    date_format(date_format(create_time, '%y-%m-%d %h:%i') - interval (minute(create_time) mod 5) minute,'%h:%i') as grouped_time,\n    count(*) as couns\nfrom \n    interface_access_frequency \nwhere  \n      date(create_time) = '2024-04-27'\ngroup by \n    grouped_time\norder by create_time desc )\nunion\nselect  date_format(grouped_time, '%h:%i') as grouped_time,0 as counts from time_intervals;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u5206\u7ec4\u6c47\u603b\u7ed3\u679c<\/strong><\/li>\n<\/ol>\n<pre>SELECT grouped_time, MAX(counts) AS counts FROM\n((SELECT \n    DATE_FORMAT(DATE_FORMAT(create_time, '%Y-%m-%d %H:%i') - INTERVAL (MINUTE(create_time) MOD 5) MINUTE,'%H:%i') AS grouped_time,\n    COUNT(*) AS counts\nFROM \n    interface_access_frequency \nWHERE  \n      DATE(create_time) = '2024-04-27'\nGROUP BY \n    grouped_time)\nUNION\nSELECT  DATE_FORMAT(grouped_time, '%H:%i') AS grouped_time,0 AS counts FROM time_intervals) a\n GROUP BY  grouped_time\nORDER BY grouped_time ASC;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6700\u7ec8\uff0c\u6211\u4eec\u5c06\u5f97\u5230\u6309\u6bcf 5 \u5206\u949f\u95f4\u9694\u6c47\u603b\u7684\u5f53\u5929\u6570\u636e\u91cf\uff0c\u5373\u4f7f\u6ca1\u6709\u6570\u636e\u4e5f\u4f1a\u8865\u96f6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528MySQL\u6309\u6bcf5\u5206\u949f\u95f4\u9694\u6c47\u603b\u4e00\u5929\u7684\u6570\u636e\u91cf\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6309\u6bcf 5 \u5206\u949f\u95f4\u9694\u6c47\u603b\u4e00\u5929\u7684\u6570\u636e\u91cf \u4e3a\u4e86\u6309\u6bcf 5 \u5206\u949f\u95f4\u9694\u6c47\u603b\u4e00\u5929\u7684\u6570\u636e\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u521b\u5efa\u65f6\u95f4\u95f4\u9694\u8868 create table time_intervals ( grouped_time time default null ); \u767b\u5f55\u540e\u590d\u5236 \u63d2\u5165\u65f6\u95f4\u95f4\u9694\u6570\u636e delimiter \/\/ create procedure inserttimeintervals() begin declare currenttime time default &#8217;00:00:00&#8242;; declare endtime time default &#8217;23:55:00&#8242;; truncate table time_intervals; while currenttime &lt;= endtime do insert into time_intervals (grouped_time) values (currenttime); set currenttime = addtime(currenttime, &#8217;00:05:00&#8242;); end while; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7878","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7878","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7878"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7878\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}