数据
------
id date money
1 20070611 100
1 20070612 100
1 20070613 100
2 20070611 100------
希望通过 "年月" 来group by ,sum(money),而现在的date字段还有 "日".该怎么才能得到
1 200706 300
2 200706 100
------
id date money
1 20070611 100
1 20070612 100
1 20070613 100
2 20070611 100------
希望通过 "年月" 来group by ,sum(money),而现在的date字段还有 "日".该怎么才能得到
1 200706 300
2 200706 100
select 1,'20070611',100 union all
select 1,'20070612',100 union all
select 1,'20070613',100 union all
select 2,'20070611',100 select
id,
substring(date,1,6) as date,
sum(money) as money
from @t
group by id,substring(date,1,6)