{"id":436,"date":"2017-08-06T12:42:51","date_gmt":"2017-08-06T04:42:51","guid":{"rendered":"https:\/\/www.dd-home.top\/?p=436"},"modified":"2017-08-06T12:42:51","modified_gmt":"2017-08-06T04:42:51","slug":"mysql-%e7%9a%84group-by-createtime","status":"publish","type":"post","link":"https:\/\/www.dd-home.top\/?p=436","title":{"rendered":"MySql \u7684group by createTime"},"content":{"rendered":"<p><!--more--><\/p>\n<p>1.\u6839\u636e\u5929\u8fdb\u884c\u5206\u7ec4<\/p>\n<p><code>SELECTSELECT DATE_FORMAT(createTime, '%Y%m%d') days, COUNT(id) COUNTFROM db_merchant_saleGROUP BY days;<\/code><\/p>\n<p>2.\u6839\u636e\u661f\u671f\u8fdb\u884c\u5206\u7ec4<\/p>\n<p><code>SELECTSELECT DATE_FORMAT(createTime, '%Y%u') weeks, COUNT(id) COUNTFROM db_merchant_saleGROUP BY weeks;<\/code><\/p>\n<p>3.\u6839\u636e\u6708\u8fdb\u884c\u5206\u7ec4<\/p>\n<p><code>SELECTSELECT DATE_FORMAT(createTime, '%Y%m') months, COUNT(id) COUNTFROM db_merchant_saleGROUP BY months<\/code><\/p>\n<p>MySql DATE_FORMAT \u683c\u5f0f\u5316\u7684\u79cd\u7c7b<\/p>\n<table class=\"dataintable\" style=\"height: 1331px;\" width=\"659\">\n<tbody>\n<tr>\n<th style=\"width: 57px;\">\u683c\u5f0f<\/th>\n<th style=\"width: 572.2px;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%a<\/td>\n<td style=\"width: 572.2px;\">\u7f29\u5199\u661f\u671f\u540d<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%b<\/td>\n<td style=\"width: 572.2px;\">\u7f29\u5199\u6708\u540d<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%c<\/td>\n<td style=\"width: 572.2px;\">\u6708\uff0c\u6570\u503c<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%D<\/td>\n<td style=\"width: 572.2px;\">\u5e26\u6709\u82f1\u6587\u524d\u7f00\u7684\u6708\u4e2d\u7684\u5929<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%d<\/td>\n<td style=\"width: 572.2px;\">\u6708\u7684\u5929\uff0c\u6570\u503c(00-31)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%e<\/td>\n<td style=\"width: 572.2px;\">\u6708\u7684\u5929\uff0c\u6570\u503c(0-31)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%f<\/td>\n<td style=\"width: 572.2px;\">\u5fae\u79d2<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%H<\/td>\n<td style=\"width: 572.2px;\">\u5c0f\u65f6 (00-23)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%h<\/td>\n<td style=\"width: 572.2px;\">\u5c0f\u65f6 (01-12)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%I<\/td>\n<td style=\"width: 572.2px;\">\u5c0f\u65f6 (01-12)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%i<\/td>\n<td style=\"width: 572.2px;\">\u5206\u949f\uff0c\u6570\u503c(00-59)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%j<\/td>\n<td style=\"width: 572.2px;\">\u5e74\u7684\u5929 (001-366)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%k<\/td>\n<td style=\"width: 572.2px;\">\u5c0f\u65f6 (0-23)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%l<\/td>\n<td style=\"width: 572.2px;\">\u5c0f\u65f6 (1-12)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%M<\/td>\n<td style=\"width: 572.2px;\">\u6708\u540d<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%m<\/td>\n<td style=\"width: 572.2px;\">\u6708\uff0c\u6570\u503c(00-12)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%p<\/td>\n<td style=\"width: 572.2px;\">AM \u6216 PM<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%r<\/td>\n<td style=\"width: 572.2px;\">\u65f6\u95f4\uff0c12-\u5c0f\u65f6\uff08hh:mm:ss AM \u6216 PM\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%S<\/td>\n<td style=\"width: 572.2px;\">\u79d2(00-59)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%s<\/td>\n<td style=\"width: 572.2px;\">\u79d2(00-59)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%T<\/td>\n<td style=\"width: 572.2px;\">\u65f6\u95f4, 24-\u5c0f\u65f6 (hh:mm:ss)<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%U<\/td>\n<td style=\"width: 572.2px;\">\u5468 (00-53) \u661f\u671f\u65e5\u662f\u4e00\u5468\u7684\u7b2c\u4e00\u5929<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%u<\/td>\n<td style=\"width: 572.2px;\">\u5468 (00-53) \u661f\u671f\u4e00\u662f\u4e00\u5468\u7684\u7b2c\u4e00\u5929<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%V<\/td>\n<td style=\"width: 572.2px;\">\u5468 (01-53) \u661f\u671f\u65e5\u662f\u4e00\u5468\u7684\u7b2c\u4e00\u5929\uff0c\u4e0e %X \u4f7f\u7528<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%v<\/td>\n<td style=\"width: 572.2px;\">\u5468 (01-53) \u661f\u671f\u4e00\u662f\u4e00\u5468\u7684\u7b2c\u4e00\u5929\uff0c\u4e0e %x \u4f7f\u7528<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%W<\/td>\n<td style=\"width: 572.2px;\">\u661f\u671f\u540d<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%w<\/td>\n<td style=\"width: 572.2px;\">\u5468\u7684\u5929 \uff080=\u661f\u671f\u65e5, 6=\u661f\u671f\u516d\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%X<\/td>\n<td style=\"width: 572.2px;\">\u5e74\uff0c\u5176\u4e2d\u7684\u661f\u671f\u65e5\u662f\u5468\u7684\u7b2c\u4e00\u5929\uff0c4 \u4f4d\uff0c\u4e0e %V \u4f7f\u7528<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%x<\/td>\n<td style=\"width: 572.2px;\">\u5e74\uff0c\u5176\u4e2d\u7684\u661f\u671f\u4e00\u662f\u5468\u7684\u7b2c\u4e00\u5929\uff0c4 \u4f4d\uff0c\u4e0e %v \u4f7f\u7528<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%Y<\/td>\n<td style=\"width: 572.2px;\">\u5e74\uff0c4 \u4f4d<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 57px;\">%y<\/td>\n<td style=\"width: 572.2px;\">\u5e74\uff0c2 \u4f4d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-436","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=436"}],"version-history":[{"count":0,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=\/wp\/v2\/posts\/436\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dd-home.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}