[MSSQL2005]月统计SQL脚本(包括没有记录的月份)
来源:互联网 发布:mac下显示隐藏文件夹 编辑:程序博客网 时间:2024/05/23 19:55
--返回年份表函数
create function dbo.getyears
()
returns @years table
(
y varchar(2)
)
as
begin
insert into @years values('01');
insert into @years values('02');
insert into @years values('03');
insert into @years values('04');
insert into @years values('05');
insert into @years values('06');
insert into @years values('07');
insert into @years values('08');
insert into @years values('09');
insert into @years values('10');
insert into @years values('11');
insert into @years values('12');
return;
end
go
--测试脚本
--临时测试用表
declare @temp table (y datetime,num int);
insert into @temp values('2009-08-10',100);
insert into @temp values('2009-09-10',200);
insert into @temp values('2009-10-10',300);
insert into @temp values('2009-10-10',400);
--统计脚本
select e.y,isnull(sum(t.num),0)
from dbo.getyears() e
left join @temp t on e.y=substring(convert(varchar(7),t.y,21),6,2)
group by e.y;
--substring(convert(varchar(7),t.y,21) 返回当前日期月份(月份不足两位时补零)
drop function dbo.getyears;
- [MSSQL2005]月统计SQL脚本(包括没有记录的月份)
- SQL统计1-12月的数据,没有数据的月份显示为0
- 用户输入日、月和年(月份可以是月份号、月份名或月份缩写),程序返回一年中到给定日子(包括这一天)的总天数
- sql月份累加统计查询
- 每个月的mongodb统计脚本
- [5月14日的脚本] 检查目前没有备份的SQL Server加密证书
- 跨年度的月份统计
- MySQL 统计过去12个月的数据(包括本月)
- 关于MSSQL2005还原数据库异常的记录
- 用sql求出两个时间之间的月份差(不足月按足月计算)
- dedecms按照月份统计文章sql语句
- 统计近12月份数据sql
- 月统计sql
- SQL获得连续的记录的统计
- 关于统计考勤记录的一段SQL
- SQl server 2008 导出脚本中包括数据项的方法
- Java使用Calendar月操作(时间段内的月份、前三个月、月份加1)
- SQL取前一个月的记录
- vim 使用技巧
- 怎样学好C#
- 基于 STAF 和 XML 配置文件的跨平台自动化测试部署
- 存储过程创建语法
- 用JDBC给存储过程传递数组类型的参数
- [MSSQL2005]月统计SQL脚本(包括没有记录的月份)
- 3月19号第一个作业:www.xml-sitemapa.com上生成的站点地图.
- 国内地图生成工具(需要支持.net framework1.0以上) 离线浏览
- the type org.hibernate.lockmode cannot be resolved
- 菁搜FTP搜索引擎 photo
- 菁搜FTP搜索引擎 photo2
- 静态链表
- 安装Office2003时提示“系统管理员设置了系统策略禁止进行此安装”
- he method get(Class, Serializable) in the type HibernateTemplate is not applicable for the arguments