<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>秘密小黑屋 &#187; 查询节点</title>
	<atom:link href="http://www.fhand.com/blog/archives/tag/%e6%9f%a5%e8%af%a2%e8%8a%82%e7%82%b9/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fhand.com/blog</link>
	<description>David&#039;s black room</description>
	<lastBuildDate>Wed, 23 Nov 2011 05:10:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[数据库]查询当前节点以及所有的下一节点的ID</title>
		<link>http://www.fhand.com/blog/archives/42.html</link>
		<comments>http://www.fhand.com/blog/archives/42.html#comments</comments>
		<pubDate>Thu, 10 Sep 2009 10:50:31 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[技术收集]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[查询节点]]></category>

		<guid isPermaLink="false">http://www.fhand.com/blog/?p=42</guid>
		<description><![CDATA[以前工作中会有比较多的SQL，但一直没有总结~ 很多都忘记了…在此做个笔记备忘 查询当前节点以及所有的下一节点的ID 表结构: Field Type Collation Null Key Default Extra Privileges Comment ——— —————- ————— —— —— ——- ————– ——————————- ——- id int(10) unsigned (NULL) NO PRI (NULL) auto_increment select,insert,update,references parent_id int(10) unsigned (NULL) YES (NULL) select,insert,update,references name varchar(255) utf8_general_ci YES (NULL) select,insert,update,references form_id int(11) (NULL) YES (NULL) select,insert,update,references path varchar(255) utf8_general_ci YES (NULL) [...]]]></description>
			<content:encoded><![CDATA[<p>以前工作中会有比较多的SQL，但一直没有总结~ 很多都忘记了…在此做个笔记备忘</p>
<blockquote><p>查询当前节点以及所有的下一节点的ID</p></blockquote>
<p>表结构:<br />
Field      Type              Collation        Null    Key     Default  Extra           Privileges                       Comment<br />
———  —————-  —————  ——  ——  ——-  ————–  ——————————-  ——-<br />
id         int(10) unsigned  (NULL)           NO      PRI     (NULL)   auto_increment  select,insert,update,references<br />
parent_id  int(10) unsigned  (NULL)           YES             (NULL)                   select,insert,update,references<br />
name       varchar(255)      utf8_general_ci  YES             (NULL)                   select,insert,update,references<br />
form_id    int(11)           (NULL)           YES             (NULL)                   select,insert,update,references<br />
path       varchar(255)      utf8_general_ci  YES             (NULL)                   select,insert,update,references</p>
<div>
<ol title="Double click to hide line number." ondblclick="linenumber(this)">
<li>select a.*,group_concat(b.id) as next from category a left join category b on a.id=b.parent_id group by a.id</li>
</ol>
</div>
<p><img src="http://i3.6.cn/cvbnm/7b/28/dc/a64daa2eee854f8dc56b8fdcb85d93f8.jpg" alt="" width="550px" /></p>
<blockquote><p>查询每个分类的前N条记录</p></blockquote>
<p>早上朋友从CSDN上介绍我看的一个帖子~ 很巧妙的解决办法~ 本来我打算用子查询limit来做…可是MYSQL不支持子查询使用limit 再仔细看这位高人的解决办法~ 确实赞~</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">   mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #808080; font-style: italic;">-- -------------------------------</span>
   mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #808080; font-style: italic;">--  Author: liangCK</span>
   mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #808080; font-style: italic;">-- -------------------------------</span>
   mysql<span style="color: #CC0099;">&gt;</span>
   mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #808080; font-style: italic;">-- &gt; 生成测试数据: @T</span>
   mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">DROP</span> <span style="color: #990099; font-weight: bold;">TABLE</span> <span style="color: #009900;">IF</span> <span style="color: #990099; font-weight: bold;">EXISTS</span> tb <span style="color: #000033;">;</span>
   Query OK<span style="color: #000033;">,</span> <span style="color: #008080;">0</span> rows affected <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.01</span> sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
   mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> tb<span style="color: #FF00FF;">&#40;</span>录象文件编号 <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">,</span>录象文件级别 <span style="color: #999900; font-weight: bold;">INT</span><span style="color: #000033;">,</span>录象文件时间 <span style="color: #999900; font-weight: bold;">TIME</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
   Query OK<span style="color: #000033;">,</span> <span style="color: #008080;">0</span> rows affected <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.05</span> sec<span style="color: #FF00FF;">&#41;</span>
&nbsp;
   mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> tb
       <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">1</span><span style="color: #000033;">,</span><span style="color: #008080;">1</span><span style="color: #000033;">,</span><span style="color: #008000;">'12:00:01'</span> <span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
       <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">2</span><span style="color: #000033;">,</span><span style="color: #008080;">1</span><span style="color: #000033;">,</span><span style="color: #008000;">'12:00:02'</span> <span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
       <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">3</span><span style="color: #000033;">,</span><span style="color: #008080;">1</span><span style="color: #000033;">,</span><span style="color: #008000;">'12:00:03'</span> <span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
       <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">4</span><span style="color: #000033;">,</span><span style="color: #008080;">2</span><span style="color: #000033;">,</span><span style="color: #008000;">'12:00:01'</span> <span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
       <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">5</span><span style="color: #000033;">,</span><span style="color: #008080;">2</span><span style="color: #000033;">,</span><span style="color: #008000;">'12:00:02'</span> <span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
       <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">6</span><span style="color: #000033;">,</span><span style="color: #008080;">2</span><span style="color: #000033;">,</span><span style="color: #008000;">'12:00:03'</span> <span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
       <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">7</span><span style="color: #000033;">,</span><span style="color: #008080;">3</span><span style="color: #000033;">,</span><span style="color: #008000;">'12:00:01'</span> <span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
       <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">8</span><span style="color: #000033;">,</span><span style="color: #008080;">3</span><span style="color: #000033;">,</span><span style="color: #008000;">'12:00:02'</span> <span style="color: #990099; font-weight: bold;">UNION</span> <span style="color: #990099; font-weight: bold;">ALL</span>
       <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #008080;">9</span><span style="color: #000033;">,</span><span style="color: #008080;">3</span><span style="color: #000033;">,</span><span style="color: #008000;">'12:00:03'</span><span style="color: #000033;">;</span>
   Query OK<span style="color: #000033;">,</span> <span style="color: #008080;">9</span> rows affected <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.09</span> sec<span style="color: #FF00FF;">&#41;</span>
   Records: <span style="color: #008080;">9</span>  Duplicates: <span style="color: #008080;">0</span>  <span style="color: #990099; font-weight: bold;">Warnings</span>: <span style="color: #008080;">0</span>
&nbsp;
   mysql<span style="color: #CC0099;">&gt;</span>
   mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #808080; font-style: italic;">-- SQL查询如下:</span>
   mysql<span style="color: #CC0099;">&gt;</span>
   mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span>
       <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">FROM</span> tb <span style="color: #990099; font-weight: bold;">AS</span> A
       <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">WHERE</span> <span style="color: #008080;">2</span><span style="color: #CC0099;">&gt;</span><span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">COUNT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #CC0099;">*</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">FROM</span> tb
       <span style="color: #CC0099;">-&gt;</span>          <span style="color: #990099; font-weight: bold;">WHERE</span> A.录象文件级别<span style="color: #CC0099;">=</span>录象文件级别
       <span style="color: #CC0099;">-&gt;</span><span style="color: #000033;">;</span>              <span style="color: #CC0099; font-weight: bold;">AND</span> 录象文件时间</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.fhand.com/blog/archives/42.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

