{"id":3670,"date":"2023-10-28T14:08:46","date_gmt":"2023-10-28T06:08:46","guid":{"rendered":"https:\/\/white-night.club\/?p=3670"},"modified":"2024-03-21T19:30:21","modified_gmt":"2024-03-21T11:30:21","slug":"ad106","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/28\/ad106\/","title":{"rendered":"1661.\u00a0\u6bcf\u53f0\u673a\u5668\u7684\u8fdb\u7a0b\u5e73\u5747\u8fd0\u884c\u65f6\u95f4"},"content":{"rendered":"\n<p>\u8868:&nbsp;<code>Activity<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| machine_id     | int     |\n| process_id     | int     |\n| activity_type  | enum    |\n| timestamp      | float   |\n+----------------+---------+\n\u8be5\u8868\u5c55\u793a\u4e86\u4e00\u5bb6\u5de5\u5382\u7f51\u7ad9\u7684\u7528\u6237\u6d3b\u52a8\u3002\n(machine_id, process_id, activity_type) \u662f\u5f53\u524d\u8868\u7684\u4e3b\u952e\uff08\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u7684\u7ec4\u5408\uff09\u3002\nmachine_id \u662f\u4e00\u53f0\u673a\u5668\u7684ID\u53f7\u3002\nprocess_id \u662f\u8fd0\u884c\u5728\u5404\u673a\u5668\u4e0a\u7684\u8fdb\u7a0bID\u53f7\u3002\nactivity_type \u662f\u679a\u4e3e\u7c7b\u578b ('start', 'end')\u3002\ntimestamp \u662f\u6d6e\u70b9\u7c7b\u578b,\u4ee3\u8868\u5f53\u524d\u65f6\u95f4(\u4ee5\u79d2\u4e3a\u5355\u4f4d)\u3002\n'start' \u4ee3\u8868\u8be5\u8fdb\u7a0b\u5728\u8fd9\u53f0\u673a\u5668\u4e0a\u7684\u5f00\u59cb\u8fd0\u884c\u65f6\u95f4\u6233 , 'end' \u4ee3\u8868\u8be5\u8fdb\u7a0b\u5728\u8fd9\u53f0\u673a\u5668\u4e0a\u7684\u7ec8\u6b62\u8fd0\u884c\u65f6\u95f4\u6233\u3002\n\u540c\u4e00\u53f0\u673a\u5668\uff0c\u540c\u4e00\u4e2a\u8fdb\u7a0b\u90fd\u6709\u4e00\u5bf9\u5f00\u59cb\u65f6\u95f4\u6233\u548c\u7ed3\u675f\u65f6\u95f4\u6233\uff0c\u800c\u4e14\u5f00\u59cb\u65f6\u95f4\u6233\u6c38\u8fdc\u5728\u7ed3\u675f\u65f6\u95f4\u6233\u524d\u9762\u3002<\/pre>\n\n\n\n<p>\u73b0\u5728\u6709\u4e00\u4e2a\u5de5\u5382\u7f51\u7ad9\u7531\u51e0\u53f0\u673a\u5668\u8fd0\u884c\uff0c\u6bcf\u53f0\u673a\u5668\u4e0a\u8fd0\u884c\u7740&nbsp;<strong>\u76f8\u540c\u6570\u91cf\u7684\u8fdb\u7a0b<\/strong>&nbsp;\u3002\u7f16\u5199\u89e3\u51b3\u65b9\u6848\uff0c\u8ba1\u7b97\u6bcf\u53f0\u673a\u5668\u5404\u81ea\u5b8c\u6210\u4e00\u4e2a\u8fdb\u7a0b\u4efb\u52a1\u7684\u5e73\u5747\u8017\u65f6\u3002<\/p>\n\n\n\n<p>\u5b8c\u6210\u4e00\u4e2a\u8fdb\u7a0b\u4efb\u52a1\u7684\u65f6\u95f4\u6307\u8fdb\u7a0b\u7684<code>'end' \u65f6\u95f4\u6233<\/code>&nbsp;\u51cf\u53bb&nbsp;<code>'start' \u65f6\u95f4\u6233<\/code>\u3002\u5e73\u5747\u8017\u65f6\u901a\u8fc7\u8ba1\u7b97\u6bcf\u53f0\u673a\u5668\u4e0a\u6240\u6709\u8fdb\u7a0b\u4efb\u52a1\u7684\u603b\u8017\u8d39\u65f6\u95f4\u9664\u4ee5\u673a\u5668\u4e0a\u7684\u603b\u8fdb\u7a0b\u6570\u91cf\u83b7\u5f97\u3002<\/p>\n\n\n\n<p>\u7ed3\u679c\u8868\u5fc5\u987b\u5305\u542b<code>machine_id\uff08\u673a\u5668ID\uff09<\/code>&nbsp;\u548c\u5bf9\u5e94\u7684&nbsp;<strong>average time\uff08\u5e73\u5747\u8017\u65f6\uff09<\/strong>&nbsp;\u522b\u540d&nbsp;<code>processing_time<\/code>\uff0c\u4e14<strong>\u56db\u820d\u4e94\u5165\u4fdd\u75593\u4f4d\u5c0f\u6570\u3002<\/strong><\/p>\n\n\n\n<p>\u4ee5&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u8fd4\u56de\u8868\u3002<\/p>\n\n\n\n<p>\u5177\u4f53\u53c2\u8003\u4f8b\u5b50\u5982\u4e0b\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>\nActivity table:\n+------------+------------+---------------+-----------+\n| machine_id | process_id | activity_type | timestamp |\n+------------+------------+---------------+-----------+\n| 0          | 0          | start         | 0.712     |\n| 0          | 0          | end           | 1.520     |\n| 0          | 1          | start         | 3.140     |\n| 0          | 1          | end           | 4.120     |\n| 1          | 0          | start         | 0.550     |\n| 1          | 0          | end           | 1.550     |\n| 1          | 1          | start         | 0.430     |\n| 1          | 1          | end           | 1.420     |\n| 2          | 0          | start         | 4.100     |\n| 2          | 0          | end           | 4.512     |\n| 2          | 1          | start         | 2.500     |\n| 2          | 1          | end           | 5.000     |\n+------------+------------+---------------+-----------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+------------+-----------------+\n| machine_id | processing_time |\n+------------+-----------------+\n| 0          | 0.894           |\n| 1          | 0.995           |\n| 2          | 1.456           |\n+------------+-----------------+\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u4e00\u5171\u67093\u53f0\u673a\u5668,\u6bcf\u53f0\u673a\u5668\u8fd0\u884c\u7740\u4e24\u4e2a\u8fdb\u7a0b.\n\u673a\u5668 0 \u7684\u5e73\u5747\u8017\u65f6: ((1.520 - 0.712) + (4.120 - 3.140)) \/ 2 = 0.894\n\u673a\u5668 1 \u7684\u5e73\u5747\u8017\u65f6: ((1.550 - 0.550) + (1.420 - 0.430)) \/ 2 = 0.995\n\u673a\u5668 2 \u7684\u5e73\u5747\u8017\u65f6: ((4.512 - 4.100) + (5.000 - 2.500)) \/ 2 = 1.456<\/pre>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>JOIN<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5468\u516d\u4e0d\u662f\u5f88\u60f3\u5237\u9898\u554a&#8230;\u5199\u70b9\u7b80\u5355\u9898\u5427\u3002<\/p>\n\n\n\n<p>\u4ec0\u4e48\u65f6\u5019\u7528\u81ea\u8054\u7ed3\uff0c\u4ec0\u4e48\u65f6\u5019\u7528\u5de6\u8054\u7ed3\u3002\u81ea\u8054\u7ed3\u6211\u5927\u6982\u80fd\u60f3\u5230\u6bcf\u4e00\u6b65\u7684\u865a\u62df\u8868\u957f\u4ec0\u4e48\u6837\u4e86\uff0c\u4f46\u662f\u5de6\u8054\u7ed3\u73b0\u5728\u5237\u7684\u9898\u8fd8\u4e0d\u591f\u591a\uff0c\u5230\u65f6\u5019\u518d\u5237\u591a\u70b9\u9898\u4f5c\u4e2a\u603b\u7ed3\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">SQL<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# Write your MySQL query statement below\nSELECT A.machine_id,ROUND(AVG(A.timestamp-B.timestamp),3) AS processing_time\nFROM Activity AS A \nJOIN Activity AS B \nON A.machine_id=B.machine_id\nWHERE A.process_id=B.process_id\nAND A.activity_type='end' AND B.activity_type='start'\nGROUP BY A.machine_id\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\"># Write your MySQL query <\/span><span style=\"color: #569CD6\">statement<\/span><span style=\"color: #D4D4D4\"> below<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">SELECT<\/span><span style=\"color: #D4D4D4\"> A.machine_id,<\/span><span style=\"color: #DCDCAA\">ROUND<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #DCDCAA\">AVG<\/span><span style=\"color: #D4D4D4\">(A.timestamp-B.timestamp),<\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> processing_time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">FROM<\/span><span style=\"color: #D4D4D4\"> Activity <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> A <\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">JOIN<\/span><span style=\"color: #D4D4D4\"> Activity <\/span><span style=\"color: #569CD6\">AS<\/span><span style=\"color: #D4D4D4\"> B <\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">ON<\/span><span style=\"color: #D4D4D4\"> A.machine_id=B.machine_id<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">WHERE<\/span><span style=\"color: #D4D4D4\"> A.process_id=B.process_id<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">AND<\/span><span style=\"color: #D4D4D4\"> A.activity_type=<\/span><span style=\"color: #CE9178\">&#39;end&#39;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">AND<\/span><span style=\"color: #D4D4D4\"> B.activity_type=<\/span><span style=\"color: #CE9178\">&#39;start&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">GROUP BY<\/span><span style=\"color: #D4D4D4\"> A.machine_id<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u81ea\u8054\u7ed3<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3670"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=3670"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3670\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=3670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}