{"id":3092,"date":"2023-10-19T09:24:18","date_gmt":"2023-10-19T01:24:18","guid":{"rendered":"https:\/\/white-night.club\/?p=3092"},"modified":"2023-11-09T11:07:48","modified_gmt":"2023-11-09T03:07:48","slug":"ad75","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/19\/ad75\/","title":{"rendered":"2329.\u00a0\u4ea7\u54c1\u9500\u552e\u5206\u6790\u2164"},"content":{"rendered":"\n<p>\u8868\uff1a<code>Sales<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| user_id     | int   |\n| quantity    | int   |\n+-------------+-------+\nsale_id \u5305\u542b\u552f\u4e00\u503c\u3002\nproduct_id \u662f Product \u8868\u7684\u5916\u952e\u3002\n\u8fd9\u4e2a\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5c55\u793a\u4e86\u4ea7\u54c1\u7684 ID \u4ee5\u53ca\u67d0\u4e2a\u7528\u6237\u8d2d\u4e70\u7684\u6570\u91cf\u3002 \n<\/pre>\n\n\n\n<p>\u8868\uff1a<code>Product<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| product_id  | int  |\n| price       | int  |\n+-------------+------+\nproduct_id \u5305\u542b\u552f\u4e00\u503c\u3002\n\u8fd9\u5f20\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u5747\u8868\u793a\u4e86\u67d0\u4e2a\u4ea7\u54c1\u7684\u4ef7\u683c\u3002\n<\/pre>\n\n\n\n<p>\u7f16\u5199\u89e3\u51b3\u65b9\u6848\uff0c\u83b7\u53d6\u6bcf\u4e2a\u7528\u6237\u7684\u6d88\u8d39\u989d\u3002<\/p>\n\n\n\n<p>\u6309\u7528\u6237\u6d88\u8d39\u989d&nbsp;<code>spending<\/code>&nbsp;<strong>\u9012\u51cf<\/strong>\u7684\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u3002\u5728\u6d88\u8d39\u989d\u76f8\u7b49\u7684\u60c5\u51b5\u4e0b\uff0c\u4ee5&nbsp;<code>user_id<\/code>&nbsp;\u9012\u589e\u7684\u987a\u5e8f\u5c06\u5176\u6392\u5e8f\u3002<\/p>\n\n\n\n<p>\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u9762\u4f8b\u5b50\u6240\u793a\uff1a<\/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>\nSales \u8868\uff1a\n+---------+------------+---------+----------+\n| sale_id | product_id | user_id | quantity |\n+---------+------------+---------+----------+\n| 1       | 1          | 101     | 10       |\n| 2       | 2          | 101     | 1        |\n| 3       | 3          | 102     | 3        |\n| 4       | 3          | 102     | 2        |\n| 5       | 2          | 103     | 3        |\n+---------+------------+---------+----------+\nProduct \u8868\uff1a\n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 1          | 10    |\n| 2          | 25    |\n| 3          | 15    |\n+------------+-------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+---------+----------+\n| user_id | spending |\n+---------+----------+\n| 101     | 125      |\n| 102     | 75       |\n| 103     | 75       |\n+---------+----------+\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u7528\u6237 101 \u7684\u6d88\u8d39\u989d\u4e3a 10 * 10 + 1 * 25 = 125 \u3002\n\u7528\u6237 102 \u7684\u6d88\u8d39\u989d\u4e3a 3 * 15 + 2 * 15 = 75 \u3002\n\u7528\u6237 103 \u7684\u6d88\u8d39\u989d\u4e3a 3 * 25 = 75 \u3002\n\u7528\u6237 101 \u6392\u5728\u6700\u524d\uff0c\u7528\u6237 102 \u4e0e\u7528\u6237 103 \u7684\u6d88\u8d39\u989d\u76f8\u540c\uff0c\u6839\u636e ID \u6211\u4eec\u53ef\u4ee5\u8fdb\u4e00\u6b65\u786e\u8ba4\u6392\u540d\uff0c\u6240\u4ee5\u7528\u6237 102 \u6392\u5728 103 \u524d\u9762\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>\u5de6\u8054\u7ed3<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u6bcf\u4e2aSales\u4e2d\u7684\u6bcf\u4e2aproduct\u4e00\u5b9a\u80fd\u5728product\u8868\u4e2d\u627e\u5230\u4e00\u4e2a\u552f\u4e00\u5bf9\u5e94\u7684\u4ea7\u54c1\u3002\u90a3\u76f4\u63a5\u5de6\u8054\u7ed3\uff0c\u518dSUM\u5b8c\u4e8b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT A.user_id,SUM(A.quantity*B.price) AS spending\r\nFROM Sales AS A\r\nLEFT JOIN Product AS B \r\nON A.product_id=B.product_id\r\nGROUP BY user_id\r\nORDER BY spending DESC<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u5de6\u8054\u7ed3+GROUP BY<\/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\/3092"}],"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=3092"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3092\/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=3092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}