易截截图软件、单文件、免安装、纯绿色、仅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] 


相关文档:

航空公司管理系统(VC++ 与SQL 2005)

系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
      这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......

在Delphi中拼装SQL语句的注意点

我使用delphi也不是很长时间,由于经常要用到SQL语句,总结了一些Delphi中使用SQL语句要注意的事项,归纳起来主要有一下几条:
一、空格不要漏:
我们经常要拼装SQL语句,特别是where条件句,在各个语句中别忘了头尾加上空格。因为在一个语句中我们会注意用空格分开关键字但是往往忘了头尾的空格。例如:
sSQL=' select ......

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 加密

use Tempdb
go
if object_ID ( 'fn_ACITEncryption' ) is not null
drop function fn_ACITEncryption
go
create function fn_ACITEncryption
(
@Str nvarchar ( 4000), -- 加密的字符串
@Flag bit = 1, --1 、加密 0 、解密
@Key nvarchar ( 50) -- 密文
)
returns nvarchar ( 4000) ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号