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


相关文档:

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 ......

怎么把 sql语句查询的值赋给变量

string str = System.Configuration.ConfigurationManager.AppSettings["strconn"];
string sqlpwd = "select password from bg_user where username='" + username + "'";
MySqlConnection conn = new MySqlConnection(str);
MySqlCommand cmd=new MySqlCommand(sqlpwd,conn);
MySqlDataAdapter adr = new MySqlDataA ......

SQL XML DELETE

--A. 从存储在非类型化的 xml 变量中的文档中删除节点
DECLARE @myDoc xml
SET @myDoc = '<?Instructions for=TheWC.exe ?>
<Root>
 <!-- instructions for the 1st work center -->
<Location LocationID="10" LaborHours="1.1" MachineHours=".2" >
 Some text 1
 <st ......

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; 字符串函数对二进制数据、字符串和 ......

sql server清除日志

1: 删除LOG (删除log文件,附加时自动重建log文件,以此方式来清空日志)
    1) 分离数据库  企业管理器->服务器->数据库->右键->分离数据库
    2) 删除LOG文件
    3) 附加数据库  企业管理器->服务器->数据库->右键->附加数据库
此法生� ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号