{"id":4145,"date":"2023-11-06T09:35:25","date_gmt":"2023-11-06T01:35:25","guid":{"rendered":"https:\/\/white-night.club\/?p=4145"},"modified":"2023-11-09T11:07:42","modified_gmt":"2023-11-09T03:07:42","slug":"ad131","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/06\/ad131\/","title":{"rendered":"1407.\u00a0\u6392\u540d\u9760\u524d\u7684\u65c5\u884c\u8005"},"content":{"rendered":"\n<p>\u8868\uff1a<code>Users<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid \u662f\u8be5\u8868\u4e2d\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u3002\nname \u662f\u7528\u6237\u540d\u5b57\u3002<\/pre>\n\n\n\n<p>\u8868\uff1a<code>Rides<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| user_id       | int     |\n| distance      | int     |\n+---------------+---------+\nid \u662f\u8be5\u8868\u4e2d\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u3002\nuser_id \u662f\u672c\u6b21\u884c\u7a0b\u7684\u7528\u6237\u7684 id, \u800c\u8be5\u7528\u6237\u6b64\u6b21\u884c\u7a0b\u8ddd\u79bb\u4e3a distance \u3002\n<\/pre>\n\n\n\n<p>\u7f16\u5199\u89e3\u51b3\u65b9\u6848\uff0c\u62a5\u544a\u6bcf\u4e2a\u7528\u6237\u7684\u65c5\u884c\u8ddd\u79bb\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u7684\u7ed3\u679c\u8868\u5355\uff0c\u4ee5&nbsp;<code>travelled_distance<\/code>&nbsp;<strong>\u964d\u5e8f\u6392\u5217<\/strong>&nbsp;\uff0c\u5982\u679c\u6709\u4e24\u4e2a\u6216\u8005\u66f4\u591a\u7684\u7528\u6237\u65c5\u884c\u4e86\u76f8\u540c\u7684\u8ddd\u79bb,&nbsp;\u90a3\u4e48\u518d\u4ee5&nbsp;<code>name<\/code>&nbsp;<strong>\u5347\u5e8f\u6392\u5217<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u7ed3\u679c\u683c\u5f0f\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>\nUsers \u8868\uff1a\n+------+-----------+\n| id   | name      |\n+------+-----------+\n| 1    | Alice     |\n| 2    | Bob       |\n| 3    | Alex      |\n| 4    | Donald    |\n| 7    | Lee       |\n| 13   | Jonathan  |\n| 19   | Elvis     |\n+------+-----------+\n\nRides \u8868\uff1a\n+------+----------+----------+\n| id   | user_id  | distance |\n+------+----------+----------+\n| 1    | 1        | 120      |\n| 2    | 2        | 317      |\n| 3    | 3        | 222      |\n| 4    | 7        | 100      |\n| 5    | 13       | 312      |\n| 6    | 19       | 50       |\n| 7    | 7        | 120      |\n| 8    | 19       | 400      |\n| 9    | 7        | 230      |\n+------+----------+----------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+----------+--------------------+\n| name     | travelled_distance |\n+----------+--------------------+\n| Elvis    | 450                |\n| Lee      | 450                |\n| Bob      | 317                |\n| Jonathan | 312                |\n| Alex     | 222                |\n| Alice    | 120                |\n| Donald   | 0                  |\n+----------+--------------------+\n<strong>\u89e3\u91ca\uff1a<\/strong>\nElvis \u548c Lee \u65c5\u884c\u4e86 450 \u82f1\u91cc\uff0cElvis \u662f\u6392\u540d\u9760\u524d\u7684\u65c5\u884c\u8005\uff0c\u56e0\u4e3a\u4ed6\u7684\u540d\u5b57\u5728\u5b57\u6bcd\u8868\u4e0a\u7684\u6392\u5e8f\u6bd4 Lee \u66f4\u5c0f\u3002\nBob, Jonathan, Alex \u548c Alice \u53ea\u6709\u4e00\u6b21\u884c\u7a0b\uff0c\u6211\u4eec\u53ea\u6309\u6b64\u6b21\u884c\u7a0b\u7684\u5168\u90e8\u8ddd\u79bb\u5bf9\u4ed6\u4eec\u6392\u5e8f\u3002\nDonald \u6ca1\u6709\u4efb\u4f55\u884c\u7a0b, \u4ed6\u7684\u65c5\u884c\u8ddd\u79bb\u4e3a 0\u3002<\/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>IFNULL<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u6311\u4e2a\u65f6\u95f4\u603b\u7ed3\u4e0bLEFT JOIN\u548cJOIN\u7684\u7528\u6cd5\uff0c\u4e0d\u7136\u770b\u5230\u76f8\u5173\u7684\u9898\u76ee\u601d\u8def\u8fd8\u662f\u6ca1\u90a3\u4e48\u660e\u786e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\nSELECT A.name,IFNULL(SUM(B.distance),0)AS travelled_distance\nFROM Users AS A \nLEFT JOIN Rides AS B \nON A.id=B.user_id \nGROUP BY A.id\nORDER BY travelled_distance DESC,A.name ASC<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1aIFNULL<\/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\/4145"}],"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=4145"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4145\/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=4145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=4145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=4145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}