table1里有两列,日期列和ID 列,我根据传进来的参数2012查与日期列相同的日期只有年分,获取了2012-1-12 10:15:00,
2012-2-12 10:15:00等许多,怎么把读到的数据的月份取出来并分组,如1,2,3,4,5,6急急急,在线等

解决方案 »

  1.   

    select 日期,datepart(mm,日期)  from table1 
    where datepart(year,日期) =2012
    group by datepart(mm,日期)
    order by  datepart(mm,日期)
      

  2.   

    我现在想统计table2里面的金钱按照table1里的日期分组统计并显示到chart控件上,table1里的ID是主键table2里的ID是外键,怎么写代码啊,求详解
      

  3.   


    declare @riqi int=2012
    select convert(varchar(7),a.riqi,120),sum(b.[金额]) as total from table1 as a with(nolock) 
    inner join table2 as b with(nolock) on a.id=b.id
    where datepart(a.riqi)=@riqi
    group by convert(varchar(7),a.riqi,120)仅供参考