{"id":4225,"date":"2023-11-07T08:58:35","date_gmt":"2023-11-07T00:58:35","guid":{"rendered":"https:\/\/white-night.club\/?p=4225"},"modified":"2023-11-09T11:07:42","modified_gmt":"2023-11-09T03:07:42","slug":"ad135","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/07\/ad135\/","title":{"rendered":"1445.\u00a0\u82f9\u679c\u548c\u6854\u5b50"},"content":{"rendered":"\n<p>\u8868:&nbsp;<code>Sales<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| sale_date     | date    |\n| fruit         | enum    | \n| sold_num      | int     | \n+---------------+---------+\n(sale_date, fruit) \u662f\u8be5\u8868\u4e3b\u952e(\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u7684\u7ec4\u5408)\u3002\n\u8be5\u8868\u5305\u542b\u4e86\u6bcf\u4e00\u5929\u4e2d\"\u82f9\u679c\" \u548c \"\u6854\u5b50\"\u7684\u9500\u552e\u60c5\u51b5\u3002\n<\/pre>\n\n\n\n<p>\u7f16\u5199\u89e3\u51b3\u65b9\u6848\u62a5\u544a\u6bcf\u4e00\u5929&nbsp;<strong>\u82f9\u679c<\/strong>&nbsp;\u548c&nbsp;<strong>\u6854\u5b50<\/strong>&nbsp;\u9500\u552e\u7684\u6570\u76ee\u7684\u5dee\u5f02.<\/p>\n\n\n\n<p>\u8fd4\u56de\u7684\u7ed3\u679c\u8868,&nbsp;\u6309\u7167\u683c\u5f0f\u4e3a&nbsp;(&#8216;YYYY-MM-DD&#8217;) \u7684&nbsp;<code>sale_date<\/code>&nbsp;\u6392\u5e8f.<\/p>\n\n\n\n<p>\u8fd4\u56de\u7ed3\u679c\u8868\u5982\u4e0b\u4f8b\u6240\u793a:<\/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>\nSales<\/code> \u8868:\n+------------+------------+-------------+\n| sale_date  | fruit      | sold_num    |\n+------------+------------+-------------+\n| 2020-05-01 | apples     | 10          |\n| 2020-05-01 | oranges    | 8           |\n| 2020-05-02 | apples     | 15          |\n| 2020-05-02 | oranges    | 15          |\n| 2020-05-03 | apples     | 20          |\n| 2020-05-03 | oranges    | 0           |\n| 2020-05-04 | apples     | 15          |\n| 2020-05-04 | oranges    | 16          |\n+------------+------------+-------------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+------------+--------------+\n| sale_date  | diff         |\n+------------+--------------+\n| 2020-05-01 | 2            |\n| 2020-05-02 | 0            |\n| 2020-05-03 | 20           |\n| 2020-05-04 | -1           |\n+------------+--------------+\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u5728 2020-05-01, \u5356\u4e86 10 \u4e2a\u82f9\u679c \u548c 8 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 10 - 8 = 2).\n\u5728 2020-05-02, \u5356\u4e86 15 \u4e2a\u82f9\u679c \u548c 15 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 15 - 15 = 0).\n\u5728 2020-05-03, \u5356\u4e86 20 \u4e2a\u82f9\u679c \u548c 0 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 20 - 0 = 20).\n\u5728 2020-05-04, \u5356\u4e86 15 \u4e2a\u82f9\u679c \u548c 16 \u4e2a\u6854\u5b50 (\u5dee\u5f02\u4e3a 15 - 16 = -1).<\/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>GROUP BY<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u81ea\u8054\u7ed3+GROUP BY\u79d2\u4e86\uff0c\u8fc7\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT A.sale_date,A.sold_num-B.sold_num AS diff\r\nFROM Sales AS A \r\nINNER JOIN Sales AS B \r\nON A.fruit='apples' AND B.fruit='oranges'\r\nAND datediff(A.sale_date,B.sale_date)=0\r\nGROUP BY A.sale_date<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1aGROUP 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\/4225"}],"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=4225"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4225\/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=4225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=4225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=4225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}