如有表
GoodsPV
ID GoodsID PVTime
1 1 2012-1-12 09:09:09
2 1 2012-2-1 10:12:00
3 2 2012-2-1 11:11:00
4 2 2012-1-28 11:00:01
然后我要查询出一个商品的每日,每周,每月的点击量
如结果为:
GoodsID PVDay PVWeek PVMonth
1 1 1 2
2 1 2 2谢谢
GoodsPV
ID GoodsID PVTime
1 1 2012-1-12 09:09:09
2 1 2012-2-1 10:12:00
3 2 2012-2-1 11:11:00
4 2 2012-1-28 11:00:01
然后我要查询出一个商品的每日,每周,每月的点击量
如结果为:
GoodsID PVDay PVWeek PVMonth
1 1 1 2
2 1 2 2谢谢
select GoodsID , convert(varchar(10),PVTime,120) PVDay , count(1) from GoodsPV group by GoodsID , convert(varchar(10),PVTime,120)--按周统计
select GoodsID , datepart(week , PVTime) PVWeek, count(1) from GoodsPV group by GoodsID , datepart(week , PVTime)
--按月统计
select GoodsID , convert(varchar(7),PVTime,120) PVMonth , count(1) from GoodsPV group by GoodsID , convert(varchar(7),PVTime,120)