{"id":4028,"date":"2023-11-03T10:48:42","date_gmt":"2023-11-03T02:48:42","guid":{"rendered":"https:\/\/white-night.club\/?p=4028"},"modified":"2023-11-09T11:07:43","modified_gmt":"2023-11-09T03:07:43","slug":"ad122","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/03\/ad122\/","title":{"rendered":"597.&nbsp;\u597d\u53cb\u7533\u8bf7 I\uff1a\u603b\u4f53\u901a\u8fc7\u7387"},"content":{"rendered":"\n<p>\u8868\uff1a<code>FriendRequest<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| sender_id      | int     |\n| send_to_id     | int     |\n| request_date   | date    |\n+----------------+---------+\n\u8be5\u8868\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\uff08\u6362\u53e5\u8bdd\u8bf4\uff0c\u5728SQL\u4e2d\uff0c\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff09\u3002\n\u8be5\u8868\u5305\u542b\u53d1\u9001\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \uff0c\u63a5\u53d7\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \u4ee5\u53ca\u8bf7\u6c42\u7684\u65e5\u671f\u3002\n<\/pre>\n\n\n\n<p>\u8868\uff1a<code>RequestAccepted<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| requester_id   | int     |\n| accepter_id    | int     |\n| accept_date    | date    |\n+----------------+---------+\n\u8be5\u8868\u53ef\u80fd\u5305\u542b\u91cd\u590d\u9879\uff08\u6362\u53e5\u8bdd\u8bf4\uff0c\u5728SQL\u4e2d\uff0c\u8be5\u8868\u6ca1\u6709\u4e3b\u952e\uff09\u3002\n\u8be5\u8868\u5305\u542b\u53d1\u9001\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \uff0c\u63a5\u53d7\u8bf7\u6c42\u7684\u7528\u6237\u7684 ID \u4ee5\u53ca\u8bf7\u6c42\u901a\u8fc7\u7684\u65e5\u671f\u3002<\/pre>\n\n\n\n<p>\u6c42\u51fa\u597d\u53cb\u7533\u8bf7\u7684\u901a\u8fc7\u7387\uff0c\u7528 2 \u4f4d\u5c0f\u6570\u8868\u793a\u3002\u901a\u8fc7\u7387\u7531\u63a5\u53d7\u597d\u53cb\u7533\u8bf7\u7684\u6570\u76ee\u9664\u4ee5\u7533\u8bf7\u603b\u6570\u3002<\/p>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li>\u901a\u8fc7\u7684\u597d\u53cb\u7533\u8bf7\u4e0d\u4e00\u5b9a\u90fd\u5728\u8868&nbsp;<code>friend_request<\/code>&nbsp;\u4e2d\u3002\u4f60\u53ea\u9700\u8981\u7edf\u8ba1\u603b\u7684\u88ab\u901a\u8fc7\u7684\u7533\u8bf7\u6570\uff08\u4e0d\u7ba1\u5b83\u4eec\u5728\u4e0d\u5728\u8868&nbsp;<code>FriendRequest<\/code>&nbsp;\u4e2d\uff09\uff0c\u5e76\u5c06\u5b83\u9664\u4ee5\u7533\u8bf7\u603b\u6570\uff0c\u5f97\u5230\u901a\u8fc7\u7387<\/li>\n\n\n\n<li>\u4e00\u4e2a\u597d\u53cb\u7533\u8bf7\u53d1\u9001\u8005\u6709\u53ef\u80fd\u4f1a\u7ed9\u63a5\u53d7\u8005\u53d1\u51e0\u6761\u597d\u53cb\u7533\u8bf7\uff0c\u4e5f\u6709\u53ef\u80fd\u4e00\u4e2a\u597d\u53cb\u7533\u8bf7\u4f1a\u88ab\u901a\u8fc7\u597d\u51e0\u6b21\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u91cd\u590d\u7684\u597d\u53cb\u7533\u8bf7\u53ea\u7edf\u8ba1\u4e00\u6b21\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u4e00\u4e2a\u597d\u53cb\u7533\u8bf7\u90fd\u6ca1\u6709\uff0c\u4f60\u5e94\u8be5\u8fd4\u56de&nbsp;<code>accept_rate<\/code>&nbsp;\u4e3a 0.00 \u3002<\/li>\n<\/ul>\n\n\n\n<p>\u8fd4\u56de\u7ed3\u679c\u5e94\u8be5\u5982\u4e0b\u4f8b\u6240\u793a\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>\nFriendRequest \u8868\uff1a\n+-----------+------------+--------------+\n| sender_id | send_to_id | request_date |\n+-----------+------------+--------------+\n| 1         | 2          | 2016\/06\/01   |\n| 1         | 3          | 2016\/06\/01   |\n| 1         | 4          | 2016\/06\/01   |\n| 2         | 3          | 2016\/06\/02   |\n| 3         | 4          | 2016\/06\/09   |\n+-----------+------------+--------------+\nRequestAccepted \u8868\uff1a\n+--------------+-------------+-------------+\n| requester_id | accepter_id | accept_date |\n+--------------+-------------+-------------+\n| 1            | 2           | 2016\/06\/03  |\n| 1            | 3           | 2016\/06\/08  |\n| 2            | 3           | 2016\/06\/08  |\n| 3            | 4           | 2016\/06\/09  |\n| 3            | 4           | 2016\/06\/10  |\n+--------------+-------------+-------------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+-------------+\n| accept_rate |\n+-------------+\n| 0.8         |\n+-------------+\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u603b\u5171\u6709 5 \u4e2a\u8bf7\u6c42\uff0c\u6709 4 \u4e2a\u4e0d\u540c\u7684\u901a\u8fc7\u8bf7\u6c42\uff0c\u6240\u4ee5\u901a\u8fc7\u7387\u662f 0.80<\/pre>\n\n\n\n<p><strong>\u8fdb\u9636:<\/strong><\/p>\n\n\n\n<ul>\n<li>\u4f60\u80fd\u5199\u4e00\u4e2a\u67e5\u8be2\u8bed\u53e5\u5f97\u5230\u6bcf\u4e2a\u6708\u7684\u901a\u8fc7\u7387\u5417\uff1f<\/li>\n\n\n\n<li>\u4f60\u80fd\u6c42\u51fa\u6bcf\u4e00\u5929\u7684\u7d2f\u8ba1\u901a\u8fc7\u7387\u5417\uff1f<\/li>\n<\/ul>\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>DISTINCT<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u8fd9\u662f\u7b80\u5355\u9898\uff1f\u8fd9\u771f\u7684\u662f\u7b80\u5355\u9898\uff1f\u6000\u7591\u4eba\u751f\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u4e24\u5f20\u8868\u90fd\u8981DISTINCT\u53bb\u91cd\uff0c\u56e0\u4e3a\u597d\u53cb\u7533\u8bf7\u53ef\u4ee5\u88ab\u53d1\u8d77\u591a\u6b21\uff0c\u4e5f\u53ef\u80fd\u88ab\u540c\u610f\u591a\u6b21\u3002\u7136\u540e\u8fd8\u8981\u8003\u8651\u4e24\u5f20\u8868\u90fd\u4e3a\u7a7a\u7684\u60c5\u51b5\u3002\n\u8bdd\u8bf4SQL\u4e2d0\u96640\u4f1a\u8fd4\u56deNULL\u554a\uff1f\u5b98\u65b9\u9898\u89e3\u7528\u7684IFNULL\uff0c\u6211\u662f\u4e0d\u662f\u80fd\u8fd9\u4e48\u7406\u89e3\uff1f<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT \r\nROUND(\r\n  IFNULL(\r\n    (SELECT COUNT(*) FROM (SELECT DISTINCT requester_id,accepter_id FROM RequestAccepted) AS A)\r\n    \/\r\n    (SELECT COUNT(*) FROM (SELECT DISTINCT sender_id,send_to_id FROM FriendRequest) AS B)\r\n    ,0\r\n  ),2\r\n)AS accept_rate<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1aDISTINCT<\/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\/4028"}],"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=4028"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4028\/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=4028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=4028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=4028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}