{"id":6788,"date":"2024-11-14T08:09:06","date_gmt":"2024-11-14T00:09:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6788\/"},"modified":"2024-11-14T08:09:06","modified_gmt":"2024-11-14T00:09:06","slug":"%e5%a6%82%e4%bd%95%e7%bb%9f%e8%ae%a1%e6%8c%87%e5%ae%9a%e6%97%b6%e9%97%b4%e8%8c%83%e5%9b%b4%e5%86%85%e8%ae%b0%e5%bd%95%e6%95%b0%e9%87%8f%e8%b6%85%e8%bf%87%e9%98%88%e5%80%bc%e7%9a%84-item_id-%e9%9b%86","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6788\/","title":{"rendered":"\u5982\u4f55\u7edf\u8ba1\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u8bb0\u5f55\u6570\u91cf\u8d85\u8fc7\u9608\u503c\u7684 item_ID \u96c6\u5408\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/172992709276131.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u7edf\u8ba1\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u8bb0\u5f55\u6570\u91cf\u8d85\u8fc7\u9608\u503c\u7684 item_ID \u96c6\u5408\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u7edf\u8ba1\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u8bb0\u5f55\u6570\u91cf\u8d85\u8fc7\u9608\u503c\u7684 item_ID \u96c6\u5408\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>sql \u7edf\u8ba1\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u7684\u8bb0\u5f55\u4e2a\u6570\u8d85\u8fc7\u6307\u5b9a\u9608\u503c\u7684\u96c6\u5408<\/strong><\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u8bb0\u5f55\u8868\uff0c\u5176\u4e2d\u5305\u542b id\u3001item_id \u548c\u8bb0\u5f55\u65f6\u95f4\uff08time\uff09\uff0c\u4efb\u52a1\u662f\u7edf\u8ba1\u51fa\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u8bb0\u5f55\u4e2a\u6570\u8d85\u8fc7\u6307\u5b9a\u9608\u503c\u7684 item_id \u96c6\u5408\u3002<\/p>\n<p>\u5047\u8bbe\u65f6\u95f4\u5355\u4f4d\u4e3a\u79d2\uff0c\u8868\u7ed3\u6784\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5217\u540d<\/th>\n<th>\u6570\u636e\u7c7b\u578b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>id<\/td>\n<td>\u81ea\u589e<\/td>\n<\/tr>\n<tr>\n<td>item_id<\/td>\n<td>\u5916\u952e<\/td>\n<\/tr>\n<tr>\n<td>time<\/td>\n<td>\u6574\u6570<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4f8b\u5982\uff0c\u8f93\u5165\u8868\u5982\u4e0b\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>item_id<\/th>\n<th>time<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>2<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>2<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>2<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>2<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>1<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td>1<\/td>\n<td>7<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>1<\/td>\n<td>7<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td>1<\/td>\n<td>8<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>2<\/td>\n<td>8<\/td>\n<\/tr>\n<tr>\n<td>11<\/td>\n<td>1<\/td>\n<td>8<\/td>\n<\/tr>\n<tr>\n<td>12<\/td>\n<td>1<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>13<\/td>\n<td>2<\/td>\n<td>11<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u76ee\u6807\u662f\u7edf\u8ba1\u51fa\u5728\u4efb\u610f\u8fde\u7eed\u7684 5 \u79d2\u65f6\u95f4\u8303\u56f4\u5185\uff0c\u8bb0\u5f55\u4e2a\u6570\u8d85\u8fc7 5 \u4e2a\u7684 item_id \u96c6\u5408\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<pre>WITH temp AS (\n  SELECT item_ID, COUNT(*) AS count_\n  FROM tableName\n  WHERE time BETWEEN (SELECT time FROM tableName ORDER BY time DESC OFFSET 5 ROWS) AND time\n  GROUP BY item_ID\n)\nSELECT DISTINCT item_ID\nFROM temp\nWHERE count_ &gt; 5;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u89e3\u91ca\uff1a<\/strong><\/p>\n<p>\u5916\u90e8 cte temp \u8ba1\u7b97\u4e86\u6bcf\u4e2a item_id \u5728\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u7684\u8bb0\u5f55\u6570\u3002\u7136\u540e\uff0c\u5916\u90e8\u67e5\u8be2\u4ece temp \u4e2d\u9009\u62e9\u8bb0\u5f55\u4e2a\u6570\u5927\u4e8e\u6307\u5b9a\u9608\u503c (5) \u7684 item_id\u3002<\/p>\n<p><strong>\u793a\u4f8b\u8f93\u51fa\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>item_id<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u7edf\u8ba1\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u8bb0\u5f55\u6570\u91cf\u8d85\u8fc7\u9608\u503c\u7684 item_ID \u96c6\u5408\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>sql \u7edf\u8ba1\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u7684\u8bb0\u5f55\u4e2a\u6570\u8d85\u8fc7\u6307\u5b9a\u9608\u503c\u7684\u96c6\u5408 \u7ed9\u5b9a\u4e00\u4e2a\u8bb0\u5f55\u8868\uff0c\u5176\u4e2d\u5305\u542b id\u3001item_id \u548c\u8bb0\u5f55\u65f6\u95f4\uff08time\uff09\uff0c\u4efb\u52a1\u662f\u7edf\u8ba1\u51fa\u6307\u5b9a\u65f6\u95f4\u8303\u56f4\u5185\u8bb0\u5f55\u4e2a\u6570\u8d85\u8fc7\u6307\u5b9a\u9608\u503c\u7684 item_id \u96c6\u5408\u3002 \u5047\u8bbe\u65f6\u95f4\u5355\u4f4d\u4e3a\u79d2\uff0c\u8868\u7ed3\u6784\u5982\u4e0b\u6240\u793a\uff1a \u5217\u540d \u6570\u636e\u7c7b\u578b id \u81ea\u589e item_id \u5916\u952e time \u6574\u6570 \u4f8b\u5982\uff0c\u8f93\u5165\u8868\u5982\u4e0b\uff1a id item_id time 1 1 1 2 2 2 3 2 2 4 2 3 5 2 3 6 1 4 7 1 7 8 1 7 9 1 8 10 2 8 11 1 8 12 1 [&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-6788","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6788","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=6788"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6788\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}