{"id":3306,"date":"2023-10-25T09:29:14","date_gmt":"2023-10-25T01:29:14","guid":{"rendered":"https:\/\/white-night.club\/?p=3306"},"modified":"2023-11-09T11:07:46","modified_gmt":"2023-11-09T03:07:46","slug":"ad94","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/25\/ad94\/","title":{"rendered":"1070.&nbsp;\u4ea7\u54c1\u9500\u552e\u5206\u6790 III"},"content":{"rendered":"\n<p>\u9500\u552e\u8868&nbsp;<code>Sales<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\n(sale_id, year) \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\uff08\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u7684\u7ec4\u5408\uff09\u3002\nproduct_id \u662f\u4ea7\u54c1\u8868\u7684\u5916\u952e\uff08reference \u5217\uff09\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u8868\u793a\uff1a\u7f16\u53f7 product_id \u7684\u4ea7\u54c1\u5728\u67d0\u4e00\u5e74\u7684\u9500\u552e\u989d\u3002\n\u8bf7\u6ce8\u610f\uff0c\u4ef7\u683c\u662f\u6309\u6bcf\u5355\u4f4d\u8ba1\u7684\u3002\n<\/pre>\n\n\n\n<p>\u4ea7\u54c1\u8868&nbsp;<code>Product<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id \u662f\u8fd9\u5f20\u8868\u7684\u4e3b\u952e\uff08\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\uff09\u3002\n\u8fd9\u5f20\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u6807\u8bc6\uff1a\u6bcf\u4e2a\u4ea7\u54c1\u7684 id \u548c \u4ea7\u54c1\u540d\u79f0\u3002<\/pre>\n\n\n\n<p>\u7f16\u5199\u89e3\u51b3\u65b9\u6848\uff0c\u9009\u51fa\u6bcf\u4e2a\u552e\u51fa\u8fc7\u7684\u4ea7\u54c1&nbsp;<strong>\u7b2c\u4e00\u5e74<\/strong>&nbsp;\u9500\u552e\u7684&nbsp;<strong>\u4ea7\u54c1 id<\/strong>\u3001<strong>\u5e74\u4efd<\/strong>\u3001<strong>\u6570\u91cf&nbsp;<\/strong>\u548c&nbsp;<strong>\u4ef7\u683c<\/strong>\u3002<\/p>\n\n\n\n<p>\u7ed3\u679c\u8868\u4e2d\u7684\u6761\u76ee\u53ef\u4ee5\u6309&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u6392\u5217\u3002<\/p>\n\n\n\n<p>\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u4f8b\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 | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\nProduct \u8868\uff1a\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+------------+------------+----------+-------+\n| product_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100        | 2008       | 10       | 5000  |\n| 200        | 2011       | 15       | 9000  |\n+------------+------------+----------+-------+<\/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>\u7a97\u53e3\u51fd\u6570<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u4e00\u5f00\u59cb\u7528\u7684row_number\uff0c\u540e\u9762\u60f3\u4e86\u60f3\u5e94\u8be5\u7528rank\u624d\u5bf9\u3002\u56e0\u4e3a\u8981\u9009\u51fa\u5168\u90e8\u7b2c\u4e00\u5e74\u7684\u4ea7\u54c1\uff0c\u800c\u4e0d\u662f\u9009\u51fa\u7b2c\u4e00\u5e74\u7684\u7b2c\u4e00\u4ef6\u4ea7\u54c1\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT product_id,year AS first_year,quantity,price\r\nFROM (\r\n  SELECT product_id,year,quantity,price,\r\n  rank()over(partition by product_id order by year) as rn\r\n  FROM Sales\r\n) t\r\nWHERE rn=1<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u7a97\u53e3\u51fd\u6570rank<\/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\/3306"}],"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=3306"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3306\/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=3306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}