L lzliang Unregistered / Unconfirmed GUEST, unregistred user! 2000-06-04 #1 在数据库中有一日期型字段Datetime,请问如何用一句SQL语言, 统计出某年(如1999年)或某月(如1999.12)其他字段的合计值?
V Victortim Unregistered / Unconfirmed GUEST, unregistred user! 2000-06-04 #2 某年:(1999) select sum(Ufiled1) as sum1 ,sum(Ufield2) as sum2 ... from Utable where (theDate>='1999-1-1') and (theDate<2000-1-1') 某年某月:(1999-12) select sum(Ufiled1) as sum1 ,sum(Ufield2) as sum2 ... from Utable where (theDate>='1999-12-1') and (theDate<2000-1-1')
某年:(1999) select sum(Ufiled1) as sum1 ,sum(Ufield2) as sum2 ... from Utable where (theDate>='1999-1-1') and (theDate<2000-1-1') 某年某月:(1999-12) select sum(Ufiled1) as sum1 ,sum(Ufield2) as sum2 ... from Utable where (theDate>='1999-12-1') and (theDate<2000-1-1')
D doud Unregistered / Unconfirmed GUEST, unregistred user! 2000-06-04 #3 什么数据库,取子串的方法也可以。 select name,substring(date,1,5),sum(a),sum(b) sum(c),sum(d) from table1 group by name,substring(date,1,5)
什么数据库,取子串的方法也可以。 select name,substring(date,1,5),sum(a),sum(b) sum(c),sum(d) from table1 group by name,substring(date,1,5)
W wumeng Unregistered / Unconfirmed GUEST, unregistred user! 2000-06-05 #5 SQL数据库: select sum(Ufiled1) sum1 ,sum(Ufield2) sum2 from Table where datepart(yy,datefiled)=1999 //1999年 //or month where datepart(mm,datefiled)=5 //5月
SQL数据库: select sum(Ufiled1) sum1 ,sum(Ufield2) sum2 from Table where datepart(yy,datefiled)=1999 //1999年 //or month where datepart(mm,datefiled)=5 //5月