{"id":820,"date":"2012-06-10T01:42:01","date_gmt":"2012-06-09T17:42:01","guid":{"rendered":"http:\/\/www.huzs.top\/?p=820"},"modified":"2012-06-10T01:42:01","modified_gmt":"2012-06-09T17:42:01","slug":"mysql-%e6%9f%a5%e8%af%a2%e8%af%ad%e5%8f%a5%e7%a4%ba%e4%be%8b%e5%85%a8%e9%9b%86-mysql%e8%af%ad%e6%b3%95%e5%a4%a7%e5%85%a8-mysql%e7%94%a8%e6%b3%95%e5%a4%a7%e5%85%a8","status":"publish","type":"post","link":"https:\/\/www.huzs.top\/?p=820","title":{"rendered":"MySQL \u67e5\u8be2\u8bed\u53e5\u793a\u4f8b\u5168\u96c6 MySQL\u8bed\u6cd5\u5927\u5168 MySQL\u7528\u6cd5\u5927\u5168"},"content":{"rendered":"<p>&#8211;\u5217\u51fapet\u6240\u6709\u7684\u5217\\nselect * from pet\\n&#8211;\u5217\u51fa\u6307\u5b9a\u7684\u5217\\nselect name, owner form pet\\n&#8211;\u76f4\u63a5\u8fdb\u884c\u7b97\u672f\u8fd0\u7b97\uff0c\u5bf9\u5b57\u6bb5\u8d77\u522b\u540d\\nselect sin(1+2) as sin\\n&#8211;where\u6761\u4ef6\\nselect * from pet where (birth&gt;&#8217;1980&#8242; and species=&#8217;dog&#8217;) or species=&#8217;bird&#8217;\\n&#8211;\u5bf9null\u7684\u6761\u4ef6\\nselect * from pet where sex is not null\\n&#8211;\u6240\u6709\u540d\u5b57\u7b2c\u56db\u4f4d\u662fn\u7684\u5ba0\u7269\u4fe1\u606f\u662f\\nselect * from pet where owner like &#8216;___n%&#8217;\\n\\n&#8211;\u6240\u6709\u4e3b\u4eba\u540d\u53ebgwen\u6216benny\u7684\u5ba0\u7269\\nselect * from pet where owner in (&#8216;gwen&#8217; , &#8216;benny&#8217;)\\n&#8211;\u67e5\u8be2\u51fa\u751f\u65e5\u671f\u572890\u5e74\u4ee3\u662f\u5ba0\u7269\uff0c\u76f8\u5f53\u4e0e &gt;= and &lt;=\\nselect * from pet where birth between &#8216;1990&#8217; and &#8216;1999&#8217;\\n&#8211;\u6309\u4e3b\u4eba\u59d3\u540d\u6392\u5e8f\uff0c\u76f8\u540c\u7684\u6309\u5ba0\u7269\u59d3\u540d\u5012\u5e8f\u6392\u5217\\nselect * from pet order by owner, name desc\\n&#8211;\u67e5\u8be2\u6027\u522b\u4e3a\u516c\u7684\u5ba0\u7269\uff0c\u6309\u751f\u65e5\u5012\u5e8f\u6392\u5217\\nselect * from pet where sex=&#8217;m&#8217; order by birth desc\\n&#8211;char_lenngth()\u8fd4\u56de\u7684\u5b57\u7b26\u7684\u957f\u5ea6\uff0clength()\u8fd4\u56de\u5b57\u8282\u957f\u5ea6\\nSELECT owner,length(owner),char_length(owner) FROM pet p;\\n<!--more-->\\n&#8211;\u5217\u51fa\u517b\u6709\u5ba0\u7269\u72d7\u7684\u4eba\u540d\\nselect distinct owner from pet where species=&#8217;dog&#8217;\\n&#8211;\u7528\u4e24\u79cd\u65b9\u6cd5\u67e5\u8be2\u51fa\u6240\u6709\u72d7\u548c\u732b\u7684\u540d\u5b57\u3001\u51fa\u751f\u5e74\u4efd\u3001\u51fa\u751f\u6708\u4efd\\nselect name, left(birth,4) as year, mid(birth, 6, 2) as month from pet\\nwhere species=&#8217;dog&#8217; or species=&#8217;cat&#8217;\\nselect name, year(birth) as year, month(birth) as month from pet\\nwhere species in(&#8216;dog&#8217;,&#8217;cat&#8217;)\\n&#8211;\u67e5\u8be2\u6240\u6709\u540d\u5b57\u4e2d\u5b58\u5728\u5b57\u6bcd&#8217;e&#8217;\u7684\u4eba\uff0c\u5c06\u4ed6\u4eec\u517b\u7684\u5ba0\u7269\u6309\u7c7b\u522b\u3001\u5e74\u9f84\u6392\u5e8f\\nselect name, species, birth\\nfrom pet\\nwhere owner like &#8216;%e%&#8217;\\norder by species,birth desc\\n&#8211;\u6570\u5b57\u51fd\u6570\\nselect round(2.345,2), truncate(2.345,2), mod(323,5)\\n&#8211;\u65e5\u671f\u51fd\u6570\\nselect now(), curdate(), curtime()\\nselect adddate(&#8216;2007-02-02&#8217;, interval 31 day)\\n&#8211;\u6c42\u51fa\u6240\u6709\u5ba0\u7269\u7684\u5e74\u9f84\\nselect name,birth,\\ntruncate(datediff(now(),birth)\/365,0) as age1,\\nyear(now())-year(birth) &#8211; (dayofyear(birth)&gt;dayofyear(now())) as age2\\nfrom pet\\n&#8211;\u5206\u7ec4\u51fd\u6570\\nselect min(birth),max(birth),avg(birth),count(*),count(sex),\\nsum(birth)\\nfrom pet\\n&#8211;\u6bcf\u79cd\u5ba0\u7269\u5404\u6709\u51e0\u53ea\\nselect species,count(*)\\nfrom pet\\ngroup by species\\n&#8211;\u67e5\u8be2\u5e74\u9f84\u6700\u5927\u7684\u5ba0\u7269\u7684\u4fe1\u606f\\nselect * from pet where birth =\\n(select max(birth) from pet)\\n&#8211;\u6bcf\u5e74\u5404\u51fa\u751f\u4e86\u51e0\u53ea\u5ba0\u7269\\nselect year(birth), count(*) from pet group by year(birth)\\n&#8211;\u9e1f\u548c\u732b\u7684\u6027\u522b\u6bd4\u4f8b\\nselect species, sex, count(*)\\nfrom pet\\nwhere species in (&#8216;cat&#8217;,&#8217;bird&#8217;)\\ngroup by species, sex\\n&#8211;\u5404\u79cd\u5ba0\u7269\u5e74\u9f84\u7684\u548c\\nselect species, sum(truncate(datediff(now(),birth)\/365,0)) as SumAge\\nfrom pet\\ngroup by species\\n&#8211;\u6570\u91cf\u5927\u4e8e1\u7684\u5ba0\u7269\u79cd\u7c7b\\nselect species, count(*) as c\\nfrom pet\\ngroup by species\\nhaving c&gt;=2\\n&#8211;\u57fa\u672c\u53cc\u8868\u5173\u8054\\nselect a.name,a.species, a.sex,b.date, b.type, b.remark\\nfrom pet a,event b\\nwhere a.name = b.name\\n&#8211;\u67e5\u8be2\u5ba0\u7269\u4ea7\u4ed4\u65f6\u7684\u5e74\u9f84\\nselect a.name, a.species,\\ntruncate(datediff(b.date,a.birth)\/365,0) as age\\nfrom pet a,event b\\nwhere a.name = b.name and b.type=&#8217;litter&#8217;\\n&#8211;90\u5e74\u4ee3\u51fa\u751f\u7684\u72d7\u7684\u4e8b\u4ef6\u5217\u8868\\nselect a.name,birth,species,sex,date,type,remark\\nfrom pet a,event b\\nwhere a.name=b.name and birth between &#8216;1990&#8217; and &#8216;1999&#8217;\\nand species=&#8217;dog&#8217;\\n&#8211;\u6d3b\u7740\u7684\u5ba0\u7269\u6309\u53d1\u751f\u7684\u4e8b\u4ef6\u7c7b\u578b\u5206\u7ec4\uff0c\u770b\u5404\u79cd\u4e8b\u4ef6\u53d1\u751f\u7684\u6b21\u6570\\nselect type, count(*)\\nfrom pet a, event b\\nwhere a.name=b.name and a.death is null\\ngroup by type\\n&#8211;\u8bb0\u5f55\u7684\u4e8b\u4ef6\u6570\u91cf\u8d85\u8fc71\u6761\u7684\u5ba0\u7269\u4fe1\u606f\\nselect a.name,species,sex,count(*)\\nfrom pet a, event b\\nwhere a.name = b.name\\ngroup by b.name\\nhaving count(*)&gt;=2\\n&#8211;\u5217\u51fa\u53d1\u751f\u4e86\u4e24\u4ef6\u4e8b\u60c5\u7684\u5ba0\u7269\u7684\u4e8b\u4ef6\u8bb0\u5f55\u4fe1\u606f\\nselect a.name,type,date,remark,b.species,b.sex,b.owner\\nfrom event a, pet b\\nwhere a.name=b.name and\\nb.name in\\n(\\nselect name\\nfrom event\\ngroup by name\\nhaving count(*)=2\\n)\\n\\n&#8211;\u63d2\u5165\u8bed\u53e5\\ninsert into pet (name,species,birth)\\nvalues (&#8216;KKK&#8217;,&#8217;snake&#8217;,&#8217;2007-01-01&#8242;);\\ninsert into pet\\nvalues (&#8216;KK&#8217;,&#8217;Diane&#8217;,&#8217;cat&#8217;,&#8217;f&#8217;,null,null);\\ninsert into pet set name=&#8217;k&#8217;,owner=&#8217;Benny&#8217;\\n\\n&#8211;\u66f4\u65b0\u8bed\u53e5\\nupdate pet set species=&#8217;snake&#8217;,sex=&#8217;f&#8217;,birth=now()\\nwhere name=&#8217;k&#8217;\\n&#8211;\u5c06\u4e8b\u4ef6\u8868\u4e2d\u751f\u65e5\u7684\u65e5\u671f\uff0c\u66f4\u65b0\u5230pet\u8868\u4e2d\u76f8\u5e94\u5ba0\u7269\u7684birth\u5b57\u6bb5\\nupdate pet a\\nset birth = (\\nselect date\\nfrom event b\\nwhere a.name=b.name and b.type=&#8217;birthday&#8217;\\n)\\nwhere a.name in (\\nselect name\\nfrom event\\nwhere type=&#8217;birthday&#8217;\\n)\\n\\n&#8211;\u5220\u9664\u8bed\u53e5\\ndelete from pet where name like &#8216;k%&#8217;\\n\\n\u6765\u6e90\uff1ahttp:\/\/www.lc365.net\/blog\/b\/15250\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8211;\u5217\u51fapet\u6240\u6709\u7684\u5217\\nselect * from pet\\n&#8211;\u5217\u51fa\u6307\u5b9a\u7684\u5217\\nsel [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-820","post","type-post","status-publish","format-standard","hentry","category-8"],"_links":{"self":[{"href":"https:\/\/www.huzs.top\/index.php?rest_route=\/wp\/v2\/posts\/820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.huzs.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.huzs.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.huzs.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.huzs.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=820"}],"version-history":[{"count":0,"href":"https:\/\/www.huzs.top\/index.php?rest_route=\/wp\/v2\/posts\/820\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.huzs.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.huzs.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.huzs.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}