{"id":4905,"date":"2023-11-13T10:36:44","date_gmt":"2023-11-13T02:36:44","guid":{"rendered":"https:\/\/white-night.club\/?p=4905"},"modified":"2023-11-16T13:00:26","modified_gmt":"2023-11-16T05:00:26","slug":"ad148","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/13\/ad148\/","title":{"rendered":"550.\u00a0\u6e38\u620f\u73a9\u6cd5\u5206\u6790 IV"},"content":{"rendered":"\n<p>Table:&nbsp;<code>Activity<\/code>+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+ | Column Name | Type | +&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+ | player_id | int | | device_id | int | | event_date | date | | games_played | int | +&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;+ \uff08player_id\uff0cevent_date\uff09\u662f\u6b64\u8868\u7684\u4e3b\u952e\uff08\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u7684\u7ec4\u5408\uff09\u3002 \u8fd9\u5f20\u8868\u663e\u793a\u4e86\u67d0\u4e9b\u6e38\u620f\u7684\u73a9\u5bb6\u7684\u6d3b\u52a8\u60c5\u51b5\u3002 \u6bcf\u4e00\u884c\u662f\u4e00\u4e2a\u73a9\u5bb6\u7684\u8bb0\u5f55\uff0c\u4ed6\u5728\u67d0\u4e00\u5929\u4f7f\u7528\u67d0\u4e2a\u8bbe\u5907\u6ce8\u9500\u4e4b\u524d\u767b\u5f55\u5e76\u73a9\u4e86\u5f88\u591a\u6e38\u620f\uff08\u53ef\u80fd\u662f 0\uff09\u3002<\/p>\n\n\n\n<p>\u7f16\u5199\u89e3\u51b3\u65b9\u6848\uff0c\u62a5\u544a\u5728\u9996\u6b21\u767b\u5f55\u7684\u7b2c\u4e8c\u5929\u518d\u6b21\u767b\u5f55\u7684\u73a9\u5bb6\u7684&nbsp;<strong>\u6bd4\u7387<\/strong>\uff0c<strong>\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u4e24\u4f4d<\/strong>\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u4f60\u9700\u8981\u8ba1\u7b97\u4ece\u9996\u6b21\u767b\u5f55\u65e5\u671f\u5f00\u59cb\u81f3\u5c11\u8fde\u7eed\u4e24\u5929\u767b\u5f55\u7684\u73a9\u5bb6\u7684\u6570\u91cf\uff0c\u7136\u540e\u9664\u4ee5\u73a9\u5bb6\u603b\u6570\u3002<\/p>\n\n\n\n<p>\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><strong>\u8f93\u5165\uff1a<\/strong> Activity table: +&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+ | player_id | device_id | event_date | games_played | +&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+ | 1 | 2 | 2016-03-01 | 5 | | 1 | 2 | 2016-03-02 | 6 | | 2 | 3 | 2017-06-25 | 1 | | 3 | 1 | 2016-03-02 | 0 | | 3 | 4 | 2018-07-03 | 5 | +&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+ <strong>\u8f93\u51fa\uff1a<\/strong> +&#8212;&#8212;&#8212;&#8211;+ | fraction | +&#8212;&#8212;&#8212;&#8211;+ | 0.33 | +&#8212;&#8212;&#8212;&#8211;+ <strong>\u89e3\u91ca\uff1a<\/strong> \u53ea\u6709 ID \u4e3a 1 \u7684\u73a9\u5bb6\u5728\u7b2c\u4e00\u5929\u767b\u5f55\u540e\u624d\u91cd\u65b0\u767b\u5f55\uff0c\u6240\u4ee5\u7b54\u6848\u662f 1\/3 = 0.33<\/p>\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 has-link-color wp-elements-c5059dbdb9d537a250b497a3ad8e314b\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>DATE_ADD\u5224\u65ad\u65e5\u671f<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u975e\u5e38\u597d\u7684\u9898\uff0c\u8ba9\u6211\u5927\u8111\u65cb\u8f6c\u4e00\u5c0f\u65f6\u3002<\/p>\n\n\n\n<p>\u8fd9\u9898\u5199\u8d77\u6765\u4e0d\u96be\uff0c\u6709\u4e0d\u8fc7\u4e24\u4e2a\u5751\u3002\u7b2c\u4e00\u4e2a\u5751\u662f\u9898\u76ee\u8981\u6c42\u7684\u9996\u6b21\u767b\u5f55\u540e\u8fde\u7eed\u767b\u5f55\u4e24\u5929\u7684\u7528\u6237\uff0c\u6240\u4ee5\u9700\u8981MIN\u6c42\u67d0\u4e2a\u7528\u6237\u7684\u9996\u6b21\u767b\u5f55\u7684\u65e5\u671f\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e8c\u4e2a\u5751\u5728\u4e8e\u65e5\u671f\u7684\u5904\u7406\u3002\u6211\u4eec\u5e38\u7528\u7684\u65f6\u95f4\u5224\u65ad\u6709\u4e24\u79cd\uff0c\u6700\u76f4\u63a5\u95ee\u9898\u4e5f\u6700\u591a\u7684\u5c31\u662fA.date+1=B.date\u3002\u6bd4\u8f83\u57fa\u7840\u7684\u5c31\u662fdatediff\u3002\u78b0\u5230\u9700\u8981\u5904\u7406\u65f6\u95f4\u7684\u9898\u7528datediff\u57fa\u672c\u90fd\u80fd\u89e3\u51b3\u3002<\/p>\n\n\n\n<p>However\uff0cdatediff\u6709\u4e2a\u5751\u3002\u5f53datediff\u78b0\u4e0a2016-02-29\u548c2016-03-01\u8fd9\u4e24\u5929\u65f6\u5c31\u4f1a\u51fa\u73b0\u95ee\u9898\uff1adatediff\u4f1a\u8fd4\u56deNULL\u3002<\/p>\n\n\n\n<p>\u6211\u4e2a\u4eba\u8ba4\u4e3a\u662fMySQL\u7684datediff\u65e0\u6cd5\u5904\u740602-29 +1 = 03-01\u8fd9\u79cd\u60c5\u51b5\uff0c\u5bf9MySQL\u6765\u8bf402-29+1=NULL\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u80fd\u7528datediff\u3002<\/p>\n\n\n\n<p>\u6700\u540e\u7528\u7684\u662fDATE_ADD\uff0cDATE_ADD\u7684\u7528\u6cd5\u5982\u56fe\uff0c\u6211\u4e2a\u4eba\u8fd8\u662f\u63a8\u8350\u53bbMySQL\u6587\u6863\u91cc\u9762\u627e\u4e0b\u76f8\u5173\u7528\u6cd5\u7684\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/654ed329ff0e6f16179663bddd33779-1024x640.png\" alt=\"\" class=\"wp-image-4911\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/654ed329ff0e6f16179663bddd33779-1024x640.png 1024w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/654ed329ff0e6f16179663bddd33779-300x188.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/654ed329ff0e6f16179663bddd33779-768x480.png 768w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/11\/654ed329ff0e6f16179663bddd33779.png 1392w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT ROUND(COUNT(IF(B.event_date IS NOT NULL,1,NULL))\/COUNT(A.player_id),2) AS fraction\r\nFROM Activity AS A \r\nLEFT JOIN Activity AS B \r\nON A.player_id=B.player_id AND date_add(A.event_date,INTERVAL 1 DAY)=B.event_date\r\nWHERE A.event_date=(\r\n  SELECT MIN(C.event_date)\r\n  FROM Activity AS C \r\n  WHERE A.player_id=C.player_id\r\n  GROUP BY C.player_id\r\n)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1aDATE_ADD\u5224\u65ad\u65e5\u671f<\/p>\n","protected":false},"author":1,"featured_media":4911,"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\/4905"}],"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=4905"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4905\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/4911"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=4905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=4905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=4905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}