<?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>9thFun~九乐 &#187; 数据库</title>
	<atom:link href="http://www.9thfun.cn/tag/%e6%95%b0%e6%8d%ae%e5%ba%93/feed" rel="self" type="application/rss+xml" />
	<link>http://www.9thfun.cn</link>
	<description>游戏策划@上海</description>
	<lastBuildDate>Fri, 25 Nov 2011 03:44:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>数值策划常用数据库语句</title>
		<link>http://www.9thfun.cn/2009/09/select-sql.html</link>
		<comments>http://www.9thfun.cn/2009/09/select-sql.html#comments</comments>
		<pubDate>Wed, 23 Sep 2009 09:46:01 +0000</pubDate>
		<dc:creator>venjet</dc:creator>
				<category><![CDATA[技术相关]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[数据库]]></category>

		<guid isPermaLink="false">http://www.9thfun.cn/?p=194</guid>
		<description><![CDATA[数值策划常常要与数据库打交道，最常见的就是每过一段时间针对游戏日志信息进行统计分析。这篇可以算是一个备忘录，venjet用到什么不容易记住语句就把它记录到这里，以后找起来也方便。对于数据库熟悉的不需要看，对数据库不熟悉的需要学习一下基础知识。所以，这篇应该算是自用的备忘（路人甲：那拜托你设成private啊private&#8230;）

1 常用函数

count()-计数

<span class="readmore"><a href="http://www.9thfun.cn/2009/09/select-sql.html" title="数值策划常用数据库语句">阅读全文——共1215字</a></span>]]></description>
			<content:encoded><![CDATA[<p>数值策划常常要与数据库打交道，最常见的就是每过一段时间针对游戏日志信息进行统计分析。这篇可以算是一个备忘录，venjet用到什么不容易记住语句就把它记录到这里，以后找起来也方便。对于数据库熟悉的不需要看，对数据库不熟悉的需要学习一下基础知识。所以，这篇应该算是自用的备忘（路人甲：那拜托你设成private啊private&#8230;）</p>
<h3>1 常用函数</h3>
<p>count()-计数</p>
<p>sum()-求和</p>
<p>min(),max()-最值</p>
<p>avg()-平均值</p>
<p>day()-取时间字段的天值，同理还有month(), year()&#8230;Access有DateValue()函数，可以根据字段内容转换成相应格式的日期。</p>
<p>hex()-十进制转为十六进制</p>
<p>left(a,b)-返回字符串a左起b个字符的部分。同理还有right()（关于中文字是1个字符还是2个字符的问题，与数据库的定序(COLLATE)有关，用的时候问下程序就行。）</p>
<p><strong>举例</strong></p>
<p>SELECT count(*) as 计数,sum([Money]) as 总和,min([Money]) as 最小值,max([Money]) as 最大值,avg([Money]) as 平均值</p>
<p><span style="background-color: #ffffff;">FROM dbo_MoneyLog_2009_05</span></p>
<p>WHERE ((dbo_MoneyLog_2009_05.[why])=”任务添加”)</p>
<p><span id="more-194"></span></p>
<h3>2 Group by子句</h3>
<p>将查询结果按照Group by后面的内容进行分类，比如Group by [ID],Group by day([Time])</p>
<p><strong>举例</strong></p>
<p><strong> </strong></p>
<p><span style="font-weight: normal;">SELECT day(TIME) as 日期,count(*) as 次数</span></p>
<p><span style="font-weight: normal;">FROM dbo_MoneyLog_2009_05</span></p>
<p><span style="font-weight: normal;">WHERE ((dbo_MoneyLog_2009_05.[why])=”捡到晶石”) group by day([TIME])</span></p>
<h3>3 UNION 操作符</h3>
<p>用来合并多个select语句的结果，合并的select列数必须一致。统计的时候常常用来将月份数据合并来统计年度数据。(不过话说月度数据出来了用excel统计年度数据更方便一点&#8230;)</p>
<p>使用上UNION ALL会列出所有的值，而UNION不会列出重复的值</p>
<p><strong>举例</strong></p>
<p>select [Times] as 时间,sum([counts]) AS 次数, Sum([Moneys]) AS 金额</p>
<p>from(SELECT DateValue([Time]) as times,count(*) AS counts, Sum([Money]) AS moneys</p>
<p>FROM dbo_MoneyLog_2009_04</p>
<p>where [why]=”捡到晶石”</p>
<p>group by DateValue([Time])</p>
<p>UNION ALL</p>
<p>SELECT DateValue([Time]) as times,count(*) AS counts, Sum([Money]) AS moneys</p>
<p>From dbo_MoneyLog_2009_05</p>
<p>where [why]=”捡到晶石”</p>
<p>GROUP BY DateValue([Time]))</p>
<p>Group by [Times]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.9thfun.cn/2009/09/select-sql.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

