{"id":2132,"date":"2022-01-12T15:41:46","date_gmt":"2022-01-12T07:41:46","guid":{"rendered":"https:\/\/7gugu.com\/?p=2132"},"modified":"2022-01-12T15:41:46","modified_gmt":"2022-01-12T07:41:46","slug":"sql-%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e6%98%a8%e6%97%a5%e6%af%8f%e4%b8%aa%e5%b0%8f%e6%97%b6%e7%9a%84%e8%ae%b0%e5%bd%95%e6%95%b0%e9%87%8f","status":"publish","type":"post","link":"https:\/\/7gugu.com\/index.php\/2022\/01\/12\/sql-%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e6%98%a8%e6%97%a5%e6%af%8f%e4%b8%aa%e5%b0%8f%e6%97%b6%e7%9a%84%e8%ae%b0%e5%bd%95%e6%95%b0%e9%87%8f\/","title":{"rendered":"[SQL] \u5982\u4f55\u83b7\u53d6\u6628\u65e5\u6bcf\u4e2a\u5c0f\u65f6\u7684\u8bb0\u5f55\u6570\u91cf?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u5229\u7528\u5de6\u8fde\u63a5\u6765\u5b9e\u73b0\u9010\u5c0f\u65f6\u67e5\u8be2(\u7ec8\u4e8e\u628a\u6570\u636e\u5e93\u539f\u7406\u5b66\u5230\u7684\u77e5\u8bc6\u7528\u4e0a\u4e86\ud83d\ude02)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>select a.click_date,ifnull(b.total,0) as total from (\nSELECT date_format(date_sub(curdate(), interval 1 HOUR),'%Y-%m-%d-%H') as click_date \nunion all \nSELECT date_format(date_sub(curdate(), interval 2 HOUR),'%Y-%m-%d-%H') as click_date \nunion all \nSELECT date_format(date_sub(curdate(), interval 3 HOUR),'%Y-%m-%d-%H') as click_date \nunion all \nSELECT date_format(date_sub(curdate(), interval 4 HOUR),'%Y-%m-%d-%H') as click_date \nunion all \nSELECT date_format(date_sub(curdate(), interval 5 HOUR),'%Y-%m-%d-%H') as click_date \nunion all \nSELECT date_format(date_sub(curdate(), interval 7 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 8 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 9 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 10 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 11 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 12 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 13 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 14 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 15 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 16 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 17 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 18 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 19 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 20 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 21 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 22 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 23 HOUR),'%Y-%m-%d-%H') as click_date\nunion all \nSELECT date_format(date_sub(curdate(), interval 24 HOUR),'%Y-%m-%d-%H') as click_date\n) a \nleft join (\nselect date_format(createTime,'%Y-%m-%d-%H') as datetime, count(*) as total from `order` where  `status` = 2 group by date_format(createTime,'%Y-%m-%d-%H')\n) b \non a.click_date = b.datetime<\/code><\/pre>\n\n\n\n<p>infull\u7528\u4e8e\u5b57\u6bb5\u7684\u88650\uff0c\u5728\u65e0\u6570\u636e\u7684\u65f6\u5019\u53ef\u4ee5\u8865\u4e0a0\u3002<\/p>\n\n\n\n<p>dateSub\u7528\u4e8e\u51cf\u53bb\u65f6\u95f4\u6233\u7684\u65f6\u95f4<\/p>\n\n\n\n<p>a\u4e3b\u8981\u662f\u7528\u6765\u751f\u6210\u9010\u5c0f\u65f6\u7684\u65f6\u95f4\u5b57\u6bb5<\/p>\n\n\n\n<p>b\u4e3b\u8981\u662f\u67e5\u8be2\u6570\u636e<\/p>\n\n\n\n<p>on\u662f\u7528\u6765\u6267\u884cleft join\u7684\u6761\u4ef6<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65b9\u6cd5 \u5229\u7528\u5de6\u8fde\u63a5\u6765\u5b9e\u73b0\u9010\u5c0f\u65f6\u67e5\u8be2(\u7ec8\u4e8e\u628a\u6570\u636e\u5e93\u539f\u7406\u5b66\u5230\u7684\u77e5\u8bc6\u7528\u4e0a\u4e86\ud83d\ude02) infull\u7528\u4e8e\u5b57\u6bb5\u7684\u88650\uff0c\u5728\u65e0\u6570\u636e\u7684 &hellip; <a href=\"https:\/\/7gugu.com\/index.php\/2022\/01\/12\/sql-%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e6%98%a8%e6%97%a5%e6%af%8f%e4%b8%aa%e5%b0%8f%e6%97%b6%e7%9a%84%e8%ae%b0%e5%bd%95%e6%95%b0%e9%87%8f\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c[SQL] \u5982\u4f55\u83b7\u53d6\u6628\u65e5\u6bcf\u4e2a\u5c0f\u65f6\u7684\u8bb0\u5f55\u6570\u91cf?\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,13],"tags":[],"class_list":["post-2132","post","type-post","status-publish","format-standard","hentry","category-29","category-13"],"_links":{"self":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts\/2132","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/comments?post=2132"}],"version-history":[{"count":0,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/posts\/2132\/revisions"}],"wp:attachment":[{"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/media?parent=2132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/categories?post=2132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/7gugu.com\/index.php\/wp-json\/wp\/v2\/tags?post=2132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}