{"id":3322,"date":"2023-10-25T18:15:03","date_gmt":"2023-10-25T10:15:03","guid":{"rendered":"https:\/\/white-night.club\/?p=3322"},"modified":"2023-11-09T11:07:46","modified_gmt":"2023-11-09T03:07:46","slug":"ad96","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/25\/ad96\/","title":{"rendered":"2837.\u00a0\u603b\u65c5\u884c\u8ddd\u79bb"},"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| user_id     | int     |\n| name        | varchar |\n+-------------+---------+\nuser_id \u662f\u6b64\u8868\u4e2d\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u3002 \n\u6b64\u8868\u7684\u6bcf\u4e00\u884c\u5305\u542b\u7528\u6237 id \u548c\u59d3\u540d\u3002\n<\/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| ride_id      | int  |\n| user_id      | int  | \n| distance     | int  |\n+--------------+------+\nride_id \u662f\u6b64\u8868\u4e2d\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u3002 \n\u6b64\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5305\u542b\u4e58\u8f66 id\u3001\u7528\u6237 id \u548c\u65c5\u884c\u8ddd\u79bb\u3002\n<\/pre>\n\n\n\n<p>\u7f16\u5199\u4e00\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u8ba1\u7b97\u6bcf\u4e2a\u7528\u6237\u7684\u65c5\u884c\u8ddd\u79bb&nbsp;<code>distance<\/code>&nbsp;\u3002\u5982\u679c\u6709\u7528\u6237\u6ca1\u6709\u4efb\u4f55\u65c5\u884c\u8bb0\u5f55\uff0c\u90a3\u4e48\u4ed6\u4eec\u7684&nbsp;<code>distance<\/code>&nbsp;\u5e94\u88ab\u89c6\u4e3a&nbsp;<code>0<\/code>&nbsp;\u3002\u8f93\u51fa&nbsp;<code>user_id<\/code>,&nbsp;<code>name<\/code>&nbsp;\u548c\u603b\u65c5\u884c\u8ddd\u79bb&nbsp;<code>traveled distance<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u6309&nbsp;<strong>\u5347\u5e8f\u6392\u5e8f<\/strong>&nbsp;\u7684&nbsp;<code>user_id<\/code>&nbsp;\u8fd4\u56de\u7ed3\u679c\u8868\u3002<\/p>\n\n\n\n<p>\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u793a\u4f8b\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 table:\n+---------+---------+\n| user_id | name    |\n+---------+---------+\n| 17      | Addison |\n| 14      | Ethan   |\n| 4       | Michael |\n| 2       | Avery   |\n| 10      | Eleanor |\n+---------+---------+\nRides table:\n+---------+---------+----------+\n| ride_id | user_id | distance |\n+---------+---------+----------+\n| 72      | 17      | 160      |\n| 42      | 14      | 161      |\n| 45      | 4       | 59       |\n| 32      | 2       | 197      |\n| 15      | 4       | 357      |\n| 56      | 2       | 196      |\n| 10      | 14      | 25       |\n+---------+---------+----------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+---------+---------+-------------------+\n| user_id | name    | traveled distance |\n+---------+---------+-------------------+\n| 2       | Avery   | 393               |\n| 4       | Michael | 416               |\n| 10      | Eleanor | 0                 |\n| 14      | Ethan   | 186               |\n| 17      | Addison | 160               |\n+---------+---------+-------------------+\n<strong>\u89e3\u91ca\uff1a<\/strong>\n-  User id \u4e3a 2 \u7684\u7528\u6237\u5b8c\u6210\u4e86\u4e24\u6b21\u65c5\u884c\uff0c\u5206\u522b\u4e3a 197 \u548c 196\uff0c\u603b\u65c5\u884c\u8ddd\u79bb\u4e3a 393\u3002\n-  User id \u4e3a 4 \u7684\u7528\u6237\u5b8c\u6210\u4e86\u4e24\u6b21\u65c5\u884c\uff0c\u5206\u522b\u4e3a 59 \u548c 357\uff0c\u603b\u65c5\u884c\u8ddd\u79bb\u4e3a 416\u3002\n-  User id \u4e3a 14 \u7684\u7528\u6237\u5b8c\u6210\u4e86\u4e24\u6b21\u65c5\u884c\uff0c\u5206\u522b\u4e3a 161 \u548c 25\uff0c\u603b\u65c5\u884c\u8ddd\u79bb\u4e3a 186\u3002\n-  User id \u4e3a 16 \u7684\u7528\u6237\u53ea\u5b8c\u6210\u4e86\u4e00\u6b21\u65c5\u884c\uff0c\u8ddd\u79bb\u4e3a 160\u3002\n-  User id \u4e3a 10 \u7684\u7528\u6237\u6ca1\u6709\u5b8c\u6210\u4efb\u4f55\u65c5\u884c\uff0c\u56e0\u6b64\u603b\u65c5\u884c\u8ddd\u79bb\u4e3a 0\u3002\n\u6309\u5347\u5e8f\u6392\u5e8f\u7684 <code>user_id<\/code> \u8fd4\u56de\u7ed3\u679c\u8868<\/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>\u9898\u763e\u72af\u4e86\uff0c\u5199\u51e0\u9053SQL\u9898\u3002<\/p>\n\n\n\n<p>\u8001\u662f\u628aifnull\u5f53\u4f5c\u63a5\u6536\u4e24\u4e2a\u53c2\u6570\u53bb\u7528\uff0c\u5e94\u8be5\u662f\u63a5\u6536\u4e24\u4e2a\u53c2\u6570\u624d\u5bf9\u3002\u524d\u4e3a\u7a7a\u8fd4\u56de\u540e\uff0c\u5426\u5219\u8fd4\u56de\u524d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT A.user_id,A.name,ifnull(SUM(B.distance),0) AS 'traveled distance'\r\nFROM Users AS A\r\nLEFT JOIN Rides AS B \r\nON A.user_id=B.user_id\r\nGROUP BY A.user_id\r\nORDER BY A.user_id ASC<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u5de6\u8054\u7ed3\u548cifnull<\/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\/3322"}],"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=3322"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3322\/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=3322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}