select ZHTSBY(在行天数本月),ZHTSLJ(在行天数累计) FROM 表 where ID=1本月合计(从上个月的26日到本月的25日为一个月)累计(从去年的12月26日到本年的12月25日为一个月) 也就是说我要统计出 在行天数本月,在行天数累计
新定义表table1,table2 declare @table1,@table2 select count(在行天数本月)as ‘月统计’,id from 表 into @table1 where id=1 and time<本月 and time>上月 select count(在行天数本月)as ‘年统计’,id from 表 into @table2 where id=1 and time<本年 and time>上年创建一个视图,将上述查询到的内容放在视图中。 create View View1 as select id,月统计,年统计 from @table1 ,@table2 where @table1.id= @table2.id好像有点啰嗦^……
Select Sum(ZHTS) From table Where ID = 1 And 时间 Between 上个月26日 And 这个月26日如果是不知道如何计算时间,可以去网上搜索下SQLSERVER的函数datepart和datediff,好像是这个两个函数,记不太清了,不好意思
上面和这个是两个不同的,谁帮忙写一个
declare @table1,@table2
select count(在行天数本月)as ‘月统计’,id from 表 into @table1 where id=1 and time<本月 and time>上月
select count(在行天数本月)as ‘年统计’,id from 表 into @table2 where id=1 and time<本年 and time>上年创建一个视图,将上述查询到的内容放在视图中。
create View View1
as select id,月统计,年统计 from @table1 ,@table2 where @table1.id= @table2.id好像有点啰嗦^……