select A.TA014 as 日期,B.TB004 as 品号,B.TB005 as 品名,B.TB006 as 规格,sum(B.TB007) as 数量,sum(B.TB011) as 金额
from INVTA A,INVTB B where A.TA001=B.TB001 and A.TA002=B.TB002  
and A.TA001 in ('1101','1103','1105','1106','1198') and A.TA014>='20120101' 
and A.TA014<='20120831' group by B.TB004,B.TB005,B.TB006
上面这条语句 我怎么按日期分别统计出一月 到八月的数量和金额呢  

解决方案 »

  1.   

    你上面这句不会报错吗?A.TA014都没包进group by,另外,麻烦给点数据和表结构出来,猜你的表和数据不容易
      

  2.   

    select SUBSTRIN(A.TA014,5,2) as 月份,B.TB004 as 品号,B.TB005 as 品名,B.TB006 as 规格,sum(B.TB007) as 数量,sum(B.TB011) as 金额
    from INVTA A,INVTB B where A.TA001=B.TB001 and A.TA002=B.TB002  
    and A.TA001 in ('1101','1103','1105','1106','1198') and A.TA014>='20120101' 
    and A.TA014<='20120831' 
    group by SUBSTRING(A.TA014,5,2), B.TB004,B.TB005,B.TB006
      

  3.   

    select SUBSTRING(A.TA014,5,2) as 月份,B.TB004 as 品号,B.TB005 as 品名,B.TB006 as 规格,sum(B.TB007) as 数量,sum(B.TB011) as 金额
    from INVTA A,INVTB B where A.TA001=B.TB001 and A.TA002=B.TB002  
    and A.TA001 in ('1101','1103','1105','1106','1198') and A.TA014>='20120101' 
    and A.TA014<='20120831' 
    group by SUBSTRING(A.TA014,5,2), B.TB004,B.TB005,B.TB006
      

  4.   

    select convert(varchar(8),A.TA014,120) as 日期,B.TB004 as 品号,B.TB005 as 品名,B.TB006 as 规格,sum(B.TB007) as 数量,sum(B.TB011) as 金额
    from INVTA A,INVTB B where A.TA001=B.TB001 and A.TA002=B.TB002  
    and A.TA001 in ('1101','1103','1105','1106','1198') and A.TA014>='20120101' 
    and A.TA014<='20120831' 
    group by convert(varchar(8),A.TA014,120),B.TB004,B.TB005,B.TB006另外一个贴好像不少人回复,你先用你的数据测试下看看