条件1,很多年的数据,对每月或者每星期做统计。
条件2,都是对单列数据统计,按月或星期。
条件2,都是对单列数据统计,按月或星期。
解决方案 »
- mssqlserver 无法启动
- sql 查询问题,非常谢谢
- 急需金蝶K3 10.2以上版本的(销售,进货,其他出入库,库存)SQL,急................
- 怎么样用T_SQL来删除赋予库与表的权限~!?
- 用sql语句,这个连接如何解决?
- SUM(CASE KM WNEN KM THEN CJ END)[KM] FROM (SELECT DISTINCT KM FROM TEST) AS A 中如何理解,其中[]是什么意思
- 有關數據庫存儲空間釋放問題?
- sql中视图的问题
- 请问VB里怎么访问SQL SERVER里建的存储过程?
- sql语句查询的写法,大侠,过来看一下!
- MS SQL语句,哪个函数可以计算一个字符串在另一个字符串出现的位置,比方说: 'AB'在'CDEAB'的位置是4,类似VB的INSTRT和EXCEL的MID
- 各位好,请教一个查询判读的逻辑问题?????
group by convert(varchar(7),convert(datetime,'2007-10-20'),120)对每星期做统计
group by dateadd(day,-datepart(weekday,convert(datetime,时间)+@@datefirst-1)+1,convert(datetime,时间))
insert into t
select '192.168.1.3','20061028140125','http://localhost/' union all
select '192.168.1.3','20061028140125','http://localhost/' union all
select '192.168.1.3','20061028140125','http://localhost/' union all
select '192.168.1.3','20061028140125','http://localhost/' union all
select '192.168.1.3','20061028140125','http://localhost/' union all
select '192.168.1.3','20061120140125','http://localhost/' union all
select '192.168.1.3','20061201140125','http://localhost/' union all
select '192.168.1.3','20061201140125','http://localhost/' union all
select '192.168.1.3','20061201140125','http://localhost/' union all
select '192.168.1.3','20061201140125','http://localhost/'
select
[每年]=(select top 1 count(*) as total from t group by left([time],8) order by total desc),
[每周]=(select top 1 count(*) as total from t group by datepart(week,left([time],8)) order by total desc),
[每月]=(select top 1 count(*) as total from t group by left([time],6) order by total desc),
[当月]=(select count(*) from t where datepart(week,left([time],8))=datepart(week,getdate())),
[当周]=(select count(*) from t where datepart(week,left([time],8))=datepart(week,getdate())-1)
SELECT STR(YEAR(DateTime))+STR(MONTH(DateTime)) AS date, MIN(DateTime) AS MinDateTime, MAX(DateTime) AS MaxDateTime, SUM(Volume)
AS Volume, MAX(HighPrice) AS highprice, MIN(LowPrice) AS lowprice
FROM FinancialNEW
GROUP BY STR(YEAR(DateTime)) + STR(MONTH(DateTime))
ORDER BY dateweek:
SELECT STR(YEAR(DateTime)) + STR(DATEPART(wk, DateTime)) AS date, MIN(DateTime) AS MinDateTime, MAX(DateTime) AS MaxDateTime, SUM(Volume)
AS Volume, MAX(HighPrice) AS highprice, MIN(LowPrice) AS lowprice
FROM FinancialNEW
GROUP BY STR(YEAR(DateTime)) + STR(DATEPART(wk, DateTime))
ORDER BY date