-->测试数据1: @Test
declare @Test table (ProName varchar(6),Price smallint,Date datetime)
insert into @Test
select '产品一',200,'2007-1-1' union all
select '产品一',240,'2007-1-3' union all
select '产品一',280,'2007-1-8' union all
select '产品一',230,'2007-2-2' union all
select '产品一',260,'2007-2-9'select ProName,Price=avg(Price),Date=convert(varchar(7),Date,120) from @Test group by ProName,convert(varchar(7),Date,120)/*
ProName Price Date
------- ----------- -------
产品一 240 2007-01
产品一 245 2007-02
*/
declare @Test table (ProName varchar(6),Price smallint,Date datetime)
insert into @Test
select '产品一',200,'2007-1-1' union all
select '产品一',240,'2007-1-3' union all
select '产品一',280,'2007-1-8' union all
select '产品一',230,'2007-2-2' union all
select '产品一',260,'2007-2-9'select ProName,Price=avg(Price),Date=convert(varchar(7),Date,120) from @Test group by ProName,convert(varchar(7),Date,120)/*
ProName Price Date
------- ----------- -------
产品一 240 2007-01
产品一 245 2007-02
*/
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货