如:我有一个名为temp的ACCESS数据库,存里有一个表名为temp
有三个字段pl,int add
pl   int   add
----------------
苹果  3     15
----------------
香蕉  4     16
----------------
雪梨  10    30
----------------
苹果  5     25
----------------
雪梨  5     15
----------------
苹果  2     10
----------------
我要做出汇总出来的结果:
并生成另一个表名为temp1的新表pl   int   add
----------------
苹果 10     50
----------------
香蕉  4     16
----------------
雪梨  15    45最好用ADO或DAO
其它方法都可以只要能做到就OK

解决方案 »

  1.   

    来了Dim conn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim sql As Stringsql = "select pl,COUNT(int),COUNT(add) from temp GROUP BY pl"
    conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\temp.mdb;Persist Security Info=False"
    conn.Open
    rs.Open sql, conn, adOpenKeyset, adLockOptimisticSet DataGrid1.DataSource = rs
      

  2.   

    rs.open "select pl,sum(int),sum(add) from temp group by pl,int,add",cn,3,3
      

  3.   

    哦,我错了,你要求和是不是,那楼上的对,哈哈select pl,sum(int),sum(add) from temp group by pl,int,add
      

  4.   

    应该只按字段P1分组成行了!将group by 子句中的int,add去掉!select pl,sum(int),sum(add) from temp group by pl
      

  5.   

    这回正确了Dim conn As New ADODB.Connection
    ss.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\temp.mdb;"  
    ss.Open
    ss.Execute "select pl,sum(int),sum(add) into " + App.Path + "\savedb.tablename from temp group by pl"
    ss.Close
    Set ss = Nothing'前提是这个temp.mdb和savedb.mdb已经存在,而tablename这个表是不存在的,就是你要从新建立的那个表,也可以保存到同一个数据库里'ss.Execute "select pl,sum(int),sum(add) into " + App.Path + "\temp.newtbl from temp group by pl"'终于可以接分了,哈哈
      

  6.   

    select pl,COUNT(int),COUNT(add) from temp GROUP BY pl