{"id":4219,"date":"2023-11-07T08:49:26","date_gmt":"2023-11-07T00:49:26","guid":{"rendered":"https:\/\/white-night.club\/?p=4219"},"modified":"2023-11-09T11:07:42","modified_gmt":"2023-11-09T03:07:42","slug":"ad134","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/07\/ad134\/","title":{"rendered":"1083.\u00a0\u9500\u552e\u5206\u6790 II"},"content":{"rendered":"\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| product_name | varchar |\n| unit_price   | int     |\n+--------------+---------+\nProduct_id \u662f\u8be5\u8868\u7684\u4e3b\u952e(\u5177\u6709\u552f\u4e00\u503c\u7684\u5217)\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u8868\u793a\u6bcf\u79cd\u4ea7\u54c1\u7684\u540d\u79f0\u548c\u4ef7\u683c\u3002\n<\/pre>\n\n\n\n<p>\u8868\uff1a<code>Sales<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| seller_id   | int     |\n| product_id  | int     |\n| buyer_id    | int     |\n| sale_date   | date    |\n| quantity    | int     |\n| price       | int     |\n+------ ------+---------+\n\u8fd9\u4e2a\u8868\u53ef\u80fd\u6709\u91cd\u590d\u7684\u884c\u3002\nproduct_id \u662f Product \u8868\u7684\u5916\u952e(reference \u5217)\u3002\nbuyer_id \u6c38\u8fdc\u4e0d\u4f1a\u662f NULL\u3002\nsale_date \u6c38\u8fdc\u4e0d\u4f1a\u662f NULL\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u4e00\u6b21\u9500\u552e\u7684\u4e00\u4e9b\u4fe1\u606f\u3002\n<\/pre>\n\n\n\n<p>\u7f16\u5199\u4e00\u4e2a\u89e3\u51b3\u65b9\u6848\uff0c\u62a5\u544a\u90a3\u4e9b\u4e70\u4e86&nbsp;<em>S8<\/em>&nbsp;\u800c\u6ca1\u6709\u4e70&nbsp;<em>iPhone<\/em>&nbsp;\u7684&nbsp;<strong>\u4e70\u5bb6<\/strong>\u3002\u6ce8\u610f\uff0c<em>S8<\/em>&nbsp;\u548c&nbsp;<em>iPhone<\/em>&nbsp;\u662f&nbsp;<code>Product<\/code>&nbsp;\u8868\u4e2d\u663e\u793a\u7684\u4ea7\u54c1\u3002<\/p>\n\n\n\n<p>\u4ee5&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u8fd4\u56de\u7ed3\u679c\u8868\u3002<\/p>\n\n\n\n<p>\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\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>\nProduct table:\n+------------+--------------+------------+\n| product_id | product_name | unit_price |\n+------------+--------------+------------+\n| 1          | S8           | 1000       |\n| 2          | G4           | 800        |\n| 3          | iPhone       | 1400       |\n+------------+--------------+------------+\n<code>Sales <\/code>table:\n+-----------+------------+----------+------------+----------+-------+\n| seller_id | product_id | buyer_id | sale_date  | quantity | price |\n+-----------+------------+----------+------------+----------+-------+\n| 1         | 1          | 1        | 2019-01-21 | 2        | 2000  |\n| 1         | 2          | 2        | 2019-02-17 | 1        | 800   |\n| 2         | 1          | 3        | 2019-06-02 | 1        | 800   |\n| 3         | 3          | 3        | 2019-05-13 | 2        | 2800  |\n+-----------+------------+----------+------------+----------+-------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+-------------+\n| buyer_id    |\n+-------------+\n| 1           |\n+-------------+\n\u89e3\u91ca\uff1a\nid \u4e3a 1 \u7684\u4e70\u5bb6\u8d2d\u4e70\u4e86\u4e00\u90e8 S8\uff0c\u4f46\u662f\u5374\u6ca1\u6709\u8d2d\u4e70 iPhone\uff0c\u800c id \u4e3a 3 \u7684\u4e70\u5bb6\u5374\u540c\u65f6\u8d2d\u4e70\u4e86\u8fd9 2 \u90e8\u624b\u673a\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>COUNT(IF\u2026)<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u901a\u8fc7COUNT(IF(condition,1,NULL))\u6765\u5224\u65ad\u67d0\u4e2a\u5177\u4f53\u6570\u636e\u51fa\u73b0\u7684\u6b21\u6570\uff0c\u6211\u8fd8\u662f\u7b2c\u4e00\u6b21\u78b0\u5230\u8fd9\u79cd\u7528\u6cd5\u3002\u4e0d\u8fc7COUNT(0)\u539f\u6765\u7b971\u554a\uff0c\u53ea\u80fd\u8fd4\u56deNULL\u624d\u80fd\u4e0d\u589e\uff0c\u86ee\u5947\u602a\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT A.buyer_id\r\nFROM Sales AS A\r\nLEFT JOIN Product AS B \r\nON A.product_id=B.product_id\r\nGROUP BY A.buyer_id\r\nHAVING COUNT(if(B.product_name='S8',1,NULL))>=1 AND\r\nCOUNT(if(B.product_name='iPhone',1,NULL))=0<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1aCOUNT(IF&#8230;)<\/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\/4219"}],"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=4219"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4219\/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=4219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=4219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=4219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}