易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL按照日、周、月、年统计数据

SQL按照日、周、月、年统计数据 收藏
文章参考:http://www.cnblogs.com/wenbhappy/archive/2008/07/02/1233660.html
如: 
表:consume_record 
字段:consume (money类型) 
date (datetime类型) 
请问怎么写四条sql语句分别按日,按周,按月,按季统计消费总量. 
如:1月 1200元 
2月 3400元 
3月 2800元 
--按日 
select sum(consume),day([date]) from consume_record where year([date]) = '2006' group by day([date]) 
--按周quarter 
select sum(consume),datename(week,[date]) from consume_record where year([date]) = '2006' group by datename(week,[date]) 
--按月 
select sum(consume),month([date]) from consume_record where year([date]) = '2006' group by month([date]) 
--按季 
select sum(consume),datename(quarter,[date]) from consume_record where year([date]) = '2006' group by datename(quarter,[date]) 
 
--指定日期你就看上面的例子变通下呀,无非就是一个聚合函数和Group by 
select [date],sum(consume) from consume_record where [date] between '2006-06-01' and '2006-07-10' group by [date] 


相关文档:

sql 表连接

TA:
1,WANG
2,ZHANG
4,LI
TB:
1,100
2,200
3,400
1.left join 左连接--以左表为基准,右表中没值的,在结果集中以null值代替。(select * from TA left join TB where TA.ID=TB.ID)
   1,WANG,100
   2,ZHANG,200
   4,NULL
2.right join 右连接--以右表为基准,左表中没值的,在 ......

MyEclipse5.5下连接Sql Server 2008的方法

下面是指导文档。请跟着一步步的做。就能成功连接上sql server 2008
 
java中连接sql server 2008的注意事项:
2000,2005的数据库驱动类的写法是:
com.microsoft.jdbc.sqlserver.SQLServerDriver
URL的写法是:假设数据库是news
jdbc:microsoft:sqlserver://localhost:1433;databaseName=news
 
但是20 ......

C++通过ADO连接ACCESS(或者SQL Server)数据库例子

#include "iostream.h"
#include "stdio.h"
#import "C:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
int main(int argc, char* argv[])
{
   ::CoInitialize(NULL);
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance("ADODB.Connection");
tr ......

SQL Server函数大全

select语句中只能使用sql函数对字段进行操作(链接sql server),
select 字段1 from 表1 where 字段1.IndexOf("云")=1;
这条语句不对的原因是indexof()函数不是sql函数,改成sql对应的函数就可以了。
left()是sql函数。
select 字段1 from 表1 where charindex('云',字段1)=1; 字符串函数对二进制数据、字符串和 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号