{"id":1441,"date":"2010-12-31T10:50:00","date_gmt":"2010-12-31T02:50:00","guid":{"rendered":""},"modified":"2013-11-23T15:20:33","modified_gmt":"2013-11-23T07:20:33","slug":"6%e4%b8%aa%e6%9c%89%e7%94%a8%e7%9a%84mysql%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1441.html","title":{"rendered":"6\u4e2a\u6709\u7528\u7684MySQL\u8bed\u53e5"},"content":{"rendered":"<p>1. \u8ba1\u7b97\u5e74\u6570<\/p>\n<p>\u4f60\u60f3\u901a\u8fc7\u751f\u65e5\u6765\u8ba1\u7b97\u8fd9\u4e2a\u4eba\u6709\u51e0\u5c81\u4e86\u3002<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(now()) \u2013 TO_DAYS(@dateofbirth)), \u2018%Y\u2019) + 0;\r\n<\/pre>\n<p>2. \u4e24\u4e2a\u65f6\u95f4\u7684\u5dee<\/p>\n<p>\u53d6\u5f97\u4e24\u4e2a datetime \u503c\u7684\u5dee\u3002\u5047\u8bbe dt1 \u548c dt2 \u662f datetime \u7c7b\u578b\uff0c\u5176\u683c\u5f0f\u4e3a \u2018yyyy-mm-dd hh:mm:ss\u2019\uff0c\u90a3\u4e48\u5b83\u4eec\u4e4b\u95f4\u6240\u5dee\u7684\u79d2\u6570\u4e3a\uff1a<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nUNIX_TIMESTAMP( dt2 ) \u2013 UNIX_TIMESTAMP( dt1 )\r\n<\/pre>\n<p>\u9664\u4ee560\u5c31\u662f\u6240\u5dee\u7684\u5206\u949f\u6570\uff0c\u9664\u4ee53600\u5c31\u662f\u6240\u5dee\u7684\u5c0f\u65f6\u6570\uff0c\u518d\u9664\u4ee524\u5c31\u662f\u6240\u5dee\u7684\u5929\u6570\u3002<\/p>\n<p>3. \u663e\u793a\u67d0\u4e00\u5217\u51fa\u73b0\u8fc7N\u6b21\u7684\u503c<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT id\r\nFROM tbl\r\nGROUP BY id\r\nHAVING COUNT(*) = N;\r\n<\/pre>\n<p>4. \u8ba1\u7b97\u4e24\u4e2a\u65e5\u5b50\u95f4\u7684\u5de5\u4f5c\u65e5<\/p>\n<p>\u6240\u8c13\u5de5\u4f5c\u65e5\u5c31\u662f\u9664\u51fa\u5468\u516d\u5468\u65e5\u548c\u8282\u5047\u65e5\u3002<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT COUNT(*)\r\nFROM calendar\r\nWHERE d BETWEEN Start AND Stop\r\n  AND DAYOFWEEK(d) NOT IN(1,7)\r\n  AND holiday=0;\r\n<\/pre>\n<p>5. \u67e5\u627e\u8868\u4e2d\u7684\u4e3b\u952e<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT k.column_name\r\nFROM information_schema.table_constraints t\r\nJOIN information_schema.key_column_usage k\r\nUSING (constraint_name,table_schema,table_name)\r\nWHERE t.constraint_type=\u2019PRIMARY KEY\u2019\r\n  AND t.table_schema=\u2019db\u2019\r\n  AND t.table_name=tbl\u2019\r\n<\/pre>\n<p>6. \u67e5\u770b\u4f60\u7684\u6570\u5e93\u6709\u591a\u5927<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nSELECT\r\n  table_schema AS \u2018Db Name\u2019,\r\n  Round( Sum( data_length + index_length ) \/ 1024 \/ 1024, 3 ) AS \u2018Db Size (MB)\u2019,\r\n  Round( Sum( data_free ) \/ 1024 \/ 1024, 3 ) AS \u2018Free Space (MB)\u2019;\r\nFROM information_schema.tables\r\nGROUP BY table_schema ;\r\n<\/pre>\n<p>\u5e0c\u671b\u5bf9\u4f60\u6709\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u8ba1\u7b97\u5e74\u6570 \u4f60\u60f3\u901a\u8fc7\u751f\u65e5\u6765\u8ba1\u7b97\u8fd9\u4e2a\u4eba\u6709\u51e0\u5c81\u4e86\u3002 SELECT DATE_FORMAT(FROM_DAYS( [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1441","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=1441"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1441\/revisions"}],"predecessor-version":[{"id":5160,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1441\/revisions\/5160"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}