﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-程序人生-随笔分类-MySQL</title><link>http://www.blogjava.net/terry6394/category/9458.html</link><description>撰写生活代码，等待编译美好人生</description><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 03:35:06 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 03:35:06 GMT</pubDate><ttl>60</ttl><item><title>[笔记]一个MySQL查询，查询指定ID的前一记录，后一记录，当前记录</title><link>http://www.blogjava.net/terry6394/archive/2006/04/06/39613.html</link><dc:creator>405 Studio</dc:creator><author>405 Studio</author><pubDate>Thu, 06 Apr 2006 08:22:00 GMT</pubDate><guid>http://www.blogjava.net/terry6394/archive/2006/04/06/39613.html</guid><wfw:comment>http://www.blogjava.net/terry6394/comments/39613.html</wfw:comment><comments>http://www.blogjava.net/terry6394/archive/2006/04/06/39613.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry6394/comments/commentRss/39613.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry6394/services/trackbacks/39613.html</trackback:ping><description><![CDATA[有些时候需要查询给定ID的前一记录后一记录和ID对应的记录。比如一些新闻系统中，通过GET方法获得文章ID需要显示“前一篇文章”“后一篇文章” 和ID指定的文章。<br />下面是我用的一种查询方法，可能效率，如果有更好的方法，请給我留言，不胜感激！<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);"> art_id, art_pdate<br /></span><span style="color: rgb(0, 0, 255);">FROM</span><span style="color: rgb(0, 0, 0);"> ecos_article<br /></span><span style="color: rgb(0, 0, 255);">WHERE</span><span style="color: rgb(0, 0, 0);"> art_id</span><span style="color: rgb(128, 128, 128);">&gt;</span><span style="color: rgb(128, 0, 0); font-weight: bold;">75</span><span style="color: rgb(0, 0, 0);"> limit </span><span style="color: rgb(128, 0, 0); font-weight: bold;">0</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0); font-weight: bold;">1</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">UNION</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">SELECT</span><span style="color: rgb(0, 0, 0);"> art_id, art_pdate<br /></span><span style="color: rgb(0, 0, 255);">FROM</span><span style="color: rgb(0, 0, 0);"> ecos_article<br /></span><span style="color: rgb(0, 0, 255);">WHERE</span><span style="color: rgb(0, 0, 0);"> art_id</span><span style="color: rgb(128, 128, 128);">&lt;=</span><span style="color: rgb(128, 0, 0); font-weight: bold;">75</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">ORDER</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">BY</span><span style="color: rgb(0, 0, 0);"> art_id </span><span style="color: rgb(0, 0, 255);">DESC</span><span style="color: rgb(0, 0, 0);"> limit </span><span style="color: rgb(128, 0, 0); font-weight: bold;">0</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(128, 0, 0); font-weight: bold;">3</span><span style="color: rgb(0, 0, 0);">;</span></div>效果如下：<br />mysql&gt; SELECT art_id, art_pdate FROM ecos_article limit 0,5;<br />+--------+------------+<br />| art_id | art_pdate  |<br />+--------+------------+<br />|     73 | 2005-12-01 |<br />|     74 | 2005-12-01 |<br />|     75 | 2005-12-01 |<br />|     76 | 2005-12-01 |<br />|     77 | 2005-12-01 |<br />+--------+------------+<br /><br />mysql&gt; SELECT art_id, art_pdate<br />    -&gt; FROM ecos_article<br />    -&gt; WHERE art_id&gt;75 limit 0,1<br />    -&gt; UNION<br />    -&gt; SELECT art_id, art_pdate<br />    -&gt; FROM ecos_article<br />    -&gt; WHERE art_id&lt;=75 ORDER BY art_id DESC limit 0,3;<br />+--------+------------+<br />| art_id | art_pdate  |<br />+--------+------------+<br />|     76 | 2005-12-01 |<br />|     75 | 2005-12-01 |<br />|     74 | 2005-12-01 |<br />+--------+------------+<br /><img src ="http://www.blogjava.net/terry6394/aggbug/39613.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry6394/" target="_blank">405 Studio</a> 2006-04-06 16:22 <a href="http://www.blogjava.net/terry6394/archive/2006/04/06/39613.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MySQL出错对照</title><link>http://www.blogjava.net/terry6394/archive/2006/04/04/39058.html</link><dc:creator>405 Studio</dc:creator><author>405 Studio</author><pubDate>Tue, 04 Apr 2006 00:18:00 GMT</pubDate><guid>http://www.blogjava.net/terry6394/archive/2006/04/04/39058.html</guid><wfw:comment>http://www.blogjava.net/terry6394/comments/39058.html</wfw:comment><comments>http://www.blogjava.net/terry6394/archive/2006/04/04/39058.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/terry6394/comments/commentRss/39058.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/terry6394/services/trackbacks/39058.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1005：创建表失败<br>在某位老兄的Blog看到的，觉得有用，Ctrl + C Ctrl + V<br>1006：创建数据库失败<br>1007：数据库已存在，创建数据库失败<br>1008：数据库不存在，删除数据库失败<br>1009：不能删除数据库文件导致删除数据库失败<br>1010：不能删除数据目录导致删除数据库失败<br>1011：删除数据库文件失败 &nbsp;&nbsp;<a href='http://www.blogjava.net/terry6394/archive/2006/04/04/39058.html'>阅读全文</a><img src ="http://www.blogjava.net/terry6394/aggbug/39058.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/terry6394/" target="_blank">405 Studio</a> 2006-04-04 08:18 <a href="http://www.blogjava.net/terry6394/archive/2006/04/04/39058.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>