{"id":3360,"date":"2023-10-26T09:22:28","date_gmt":"2023-10-26T01:22:28","guid":{"rendered":"https:\/\/white-night.club\/?p=3360"},"modified":"2023-11-09T11:07:46","modified_gmt":"2023-11-09T03:07:46","slug":"ad100","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/26\/ad100\/","title":{"rendered":"1596.\u00a0\u6bcf\u4f4d\u987e\u5ba2\u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1"},"content":{"rendered":"\n<p>\u8868\uff1a<code>Customers<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n+---------------+---------+\ncustomer_id \u662f\u8be5\u8868\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\n\u8be5\u8868\u5305\u542b\u6240\u6709\u987e\u5ba2\u7684\u4fe1\u606f\n<\/pre>\n\n\n\n<p>\u8868\uff1a<code>Orders<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| order_id      | int     |\n| order_date    | date    |\n| customer_id   | int     |\n| product_id    | int     |\n+---------------+---------+\norder_id \u662f\u8be5\u8868\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\n\u8be5\u8868\u5305\u542b\u987e\u5ba2 customer_id \u7684\u8ba2\u5355\u4fe1\u606f\n\u6ca1\u6709\u987e\u5ba2\u4f1a\u5728\u4e00\u5929\u5185\u8ba2\u8d2d\u76f8\u540c\u7684\u5546\u54c1<strong> \u591a\u4e8e\u4e00\u6b21<\/strong><\/pre>\n\n\n\n<p>\u8868\uff1a<code>Products<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| product_name  | varchar |\n| price         | int     |\n+---------------+---------+\nproduct_id \u662f\u8be5\u8868\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\n\u8be5\u8868\u5305\u542b\u4e86\u6240\u6709\u5546\u54c1\u7684\u4fe1\u606f\n<\/pre>\n\n\n\n<p>\u5199\u4e00\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u627e\u5230\u6bcf\u4e00\u4e2a\u987e\u5ba2\u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1\u3002<\/p>\n\n\n\n<p>\u7ed3\u679c\u8868\u5355\u5e94\u8be5\u6709\u6bcf\u4e00\u4f4d\u81f3\u5c11\u4e0b\u8fc7\u4e00\u6b21\u5355\u7684\u987e\u5ba2&nbsp;<code>customer_id<\/code>&nbsp;,&nbsp;\u4ed6\u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1\u7684&nbsp;<code>product_id<\/code>&nbsp;\u548c&nbsp;<code>product_name<\/code>\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u7ed3\u679c<strong>&nbsp;\u6ca1\u6709\u987a\u5e8f\u8981\u6c42<\/strong>\u3002<\/p>\n\n\n\n<p>\u67e5\u8be2\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\"><code><strong>\u8f93\u5165\uff1a<\/strong>\nCustomers\u8868\uff1a<\/code>\n+-------------+-------+\n| customer_id | name  |\n+-------------+-------+\n| 1           | Alice |\n| 2           | Bob   |\n| 3           | Tom   |\n| 4           | Jerry |\n| 5           | John  |\n+-------------+-------+\n<code>Orders\u8868\uff1a<\/code>\n+----------+------------+-------------+------------+\n| order_id | order_date | customer_id | product_id |\n+----------+------------+-------------+------------+\n| 1        | 2020-07-31 | 1           | 1          |\n| 2        | 2020-07-30 | 2           | 2          |\n| 3        | 2020-08-29 | 3           | 3          |\n| 4        | 2020-07-29 | 4           | 1          |\n| 5        | 2020-06-10 | 1           | 2          |\n| 6        | 2020-08-01 | 2           | 1          |\n| 7        | 2020-08-01 | 3           | 3          |\n| 8        | 2020-08-03 | 1           | 2          |\n| 9        | 2020-08-07 | 2           | 3          |\n| 10       | 2020-07-15 | 1           | 2          |\n+----------+------------+-------------+------------+\n<code>Products\u8868\uff1a<\/code>\n+------------+--------------+-------+\n| product_id | product_name | price |\n+------------+--------------+-------+\n| 1          | keyboard     | 120   |\n| 2          | mouse        | 80    |\n| 3          | screen       | 600   |\n| 4          | hard disk    | 450   |\n+------------+--------------+-------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+-------------+------------+--------------+\n| customer_id | product_id | product_name |\n+-------------+------------+--------------+\n| 1           | 2          | mouse        |\n| 2           | 1          | keyboard     |\n| 2           | 2          | mouse        |\n| 2           | 3          | screen       |\n| 3           | 3          | screen       |\n| 4           | 1          | keyboard     |\n+-------------+------------+--------------+\n<strong>\u89e3\u91ca\uff1a<\/strong>\nAlice (customer 1) \u4e09\u6b21\u8ba2\u8d2d\u9f20\u6807, \u4e00\u6b21\u8ba2\u8d2d\u952e\u76d8, \u6240\u4ee5\u9f20\u6807\u662f Alice \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nBob (customer 2) \u4e00\u6b21\u8ba2\u8d2d\u952e\u76d8, \u4e00\u6b21\u8ba2\u8d2d\u9f20\u6807, \u4e00\u6b21\u8ba2\u8d2d\u663e\u793a\u5668, \u6240\u4ee5\u8fd9\u4e9b\u90fd\u662f Bob \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nTom (customer 3) \u53ea\u4e24\u6b21\u8ba2\u8d2d\u663e\u793a\u5668, \u6240\u4ee5\u663e\u793a\u5668\u662f Tom \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nJerry (customer 4) \u53ea\u4e00\u6b21\u8ba2\u8d2d\u952e\u76d8, \u6240\u4ee5\u952e\u76d8\u662f Jerry \u6700\u7ecf\u5e38\u8ba2\u8d2d\u7684\u5546\u54c1.\nJohn (customer 5) \u6ca1\u6709\u8ba2\u8d2d\u8fc7\u5546\u54c1, \u6240\u4ee5\u6211\u4eec\u5e76\u6ca1\u6709\u628a John \u5305\u542b\u5728\u7ed3\u679c\u8868\u4e2d.<\/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>COUNT<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u7b97\u662f\u80fd\u81ea\u5df1\u5199\u51fa\u4e2d\u7b49\u96be\u5ea6\u7684SQL\u9898\u4e86\uff0c\u4ee4\u4eba\u611f\u6168\u3002<\/p>\n\n\n\n<p>\u987a\u4fbf\u8bb0\u5f55\u4e0bSQL\u4e66\u5199\u7684\u987a\u5e8f\uff0c\u5148WHERE\uff0c\u518d\u662fGROUP BY\u548cHAVING\u3002WHERE\u7b2c\u4e00\u6b21\u7b5b\u9009\uff0cHAVING\u7684\u76ee\u7684\u662f\u5bf9\u5206\u7ec4\u7684\u6570\u636e\u518d\u8fdb\u884c\u7b5b\u9009\uff0c\u6240\u4ee5\u524d\u9762\u8981\u5148\u5206\u7ec4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT A.customer_id,B.product_id,C.product_name\r\nFROM Customers AS A,Orders AS B,Products AS C \r\nWHERE A.customer_id=B.customer_id AND B.product_id=C.product_id\r\nGROUP BY A.customer_id,B.product_id\r\nHAVING COUNT(C.product_name)>=(\r\n  SELECT COUNT(D.product_id)\r\n  FROM Orders AS D\r\n  WHERE A.customer_id=D.customer_id\r\n  GROUP BY D.customer_id,D.product_id\r\n  ORDER BY COUNT(D.product_id) DESC\r\n  LIMIT 1\r\n)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1aCOUNT<\/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\/3360"}],"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=3360"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3360\/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=3360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}