<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[mysql 将null转代为0]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 26 Jan 2011 04:45:16 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	IFNULL()返回一个数字或字符串值，取决于它被使用的上下文环境：<br/><div class="code">cat fushuQQCheck.txt &#124;awk &#039;&#123;print &quot;select &quot;$1 &quot;,(select sum(FScore) from&nbsp;&nbsp;Tbl_ScoreDetail_&quot; substr($1,length($1)-1,2) &quot;&nbsp;&nbsp;where FDesId=&#039;&#92;&#039;&#039;&quot;$1 &quot;&#039;&#92;&#039;&#039; and FSType=1)-IFNULL((select sum(FScore) from&nbsp;&nbsp;Tbl_ScoreDetail_&quot; substr($1,length($1)-1,2) &quot; where FDesId=&#039;&#92;&#039;&#039;&quot; $1 &quot;&#039;&#92;&#039;&#039; and FSType=0),0); &quot;&#125;&#039;</div><br/><br/>1、如果为空返回0<br/>select ifnull(null,0)<br/>2、如果为空返回0，否则返回1<br/>select if(isnull(col),0,1) as col.<br/>MYSQL 中的IFNULL函数<br/>IFNULL(expr1,expr2) <br/>如果expr1不是NULL，IFNULL()返回expr1，否则它返回expr2。IFNULL()返回一个数字或字符串值，取决于它被使用的上下文环境。 <br/>mysql&gt; select IFNULL(1,0);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt; 1<br/>mysql&gt; select IFNULL(0,10);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt; 0<br/>mysql&gt; select IFNULL(1/0,10);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt; 10<br/>mysql&gt; select IFNULL(1/0,&#039;yes&#039;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt; &#039;yes&#039;<br/><br/>IF(expr1,expr2,expr3) <br/>如果expr1是TRUE(expr1&lt;&gt;0且expr1&lt;&gt;NULL)，那么IF()返回expr2，否则它返回expr3。IF()返回一个数字或字符串值，取决于它被使用的上下文。 <br/>mysql&gt; select IF(1&gt;2,2,3);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt; 3<br/>mysql&gt; select IF(1&lt;2,&#039;yes&#039;,&#039;no&#039;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt; &#039;yes&#039;<br/>mysql&gt; select IF(strcmp(&#039;test&#039;,&#039;test1&#039;),&#039;yes&#039;,&#039;no&#039;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt; &#039;no&#039;<br/>expr1作为整数值被计算，它意味着如果你正在测试浮点或字符串值，你应该使用一个比较操作来做。 <br/>mysql&gt; select IF(0.1,1,0);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt; 0<br/>mysql&gt; select IF(0.1&lt;&gt;0,1,0);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt; 1<br/>在上面的第一种情况中，IF(0.1)返回0，因为0.1被变换到整数值, 导致测试IF(0)。这可能不是你期望的。在第二种情况中，比较测试原来的浮点值看它是否是非零，比较的结果被用作一个整数。 <br/>CASE value WHEN [compare-value] THEN result [WHEN [compare-value] THEN result ...] [ELSE result] END <br/>　 <br/>CASE WHEN [condition] THEN result [WHEN [condition] THEN result ...] [ELSE result] END <br/>第一个版本返回result，其中value=compare-value。第二个版本中如果第一个条件为真，返回result。如果没有匹配的result值，那么结果在ELSE后的result被返回。如果没有ELSE部分，那么NULL被返回。 <br/>mysql&gt; SELECT CASE 1 WHEN 1 THEN &quot;one&quot; WHEN 2 THEN &quot;two&quot; ELSE &quot;more&quot; END;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt; &quot;one&quot;<br/>mysql&gt; SELECT CASE WHEN 1&gt;0 THEN &quot;true&quot; ELSE &quot;false&quot; END;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt; &quot;true&quot;<br/>mysql&gt; SELECT CASE BINARY &quot;B&quot; when &quot;a&quot; then 1 when &quot;b&quot; then 2 END;<br/>-&gt; NULL <br/>来源：http://blog.163.com/love-love-l/blog/static/21078304201002034639214/
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] mysql 将null转代为0]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>