我的数据库里面有这样4个字段
name,moneya,moneyb,   day | 数据库的名字是home
名字  应交   已交     日期
text  integer integer data|
------------------------
我想计算这一个月的已交数值,也就是统计这个月的已交金额
比如我要计算2003年1月21日到2003年2月21日的数值
或者我就要计算2003年一月份的数值,sql的语句应该怎么写
最好能够详细一点说,在线等待,正确的话立即给分

解决方案 »

  1.   

    select sum(moneyb) from 表名 where 日期>='2003-1-21' and 日期<='2003-2-21'
      

  2.   

    i will try waiting ...
      

  3.   

    如果是所有的名字的已交那么:
    home.excute select sum(moneyb) from (table name) where date >='2003-1-21' and date<='2003-2-21'
    如果是要每个名字的已交那么:
    home.excute select name,sum(moneyb) from (table name) where date>='2003-1-21' and date<='2003-2-21' group by name
      

  4.   

    Option Explicit
    '添加ADO引用Dim cn As New ADODB.Connection
    Dim rs As New ADODB.RecordsetPrivate Sub Command1_Click()
        Dim fsum As Long
        Set rs = cn.Execute("select sum(moneyb) from 表名 where 日期 bewteen #2003-1-21# and #2003-2-21#")
        fsum = rs.Fields(0)
    End Sub'一月份
    Private Sub Command2_Click()
        Dim fsum As Long
        Set rs = cn.Execute("select sum(moneyb) from 表名 where month(日期)=1")
        fsum = rs.Fields(0)
    End SubPrivate Sub Form_Load()
        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\home.MDB;Persist Security Info=False"
        cn.Open
        
    End Sub
      

  5.   

    select isnull(sum(moneya),0) as moneya ,isnull(sum(moneyb),0) as moneyb from home where day between '2003-1-21' and '2003-2-21'
      

  6.   

    楼上的是针对access数据库的.
    下面是sql server数据库
    select sum(moneyb) from 表名 where 日期>='2003-1-21' and 日期<='2003-2-21'
      

  7.   

    select sum(moneyb) from home where day between cdate('2003/01/21') and cdate('2003/02/21')