表A
bdepart  char(12)
salary1  float
salary2  float
salary3  float
salary4  float
salary5  float
salary6  float
salary7  float
salary8  float
salary9  float
erji     char(1)
bdepartpid char(4)现在想把数据根据条件汇总到一张汇总表B里作统计然后绑定到GridView
表B
bdepart  char(12)
tongji1  float 条件1
tongji2  float 条件2
....其中数据汇方法如下:
先select distinct bdepart from A where erji='t' order by bdepartpid
  for i=0 to bdepart的记录数
     select sum(salary1) from A where bdepart=@bdepart
     插sum(salary1)到表B的tongji[i]中
  next请问这样的后台语法如何写呀?(顺便问一下,是像我这样写好还是先放到dataset再插到数据库?)

解决方案 »

  1.   

    先从A表读出数据(筛选条件:select distinct bdepart from A where erji='t' order by bdepartpid),并将读出的sum(salary1)...等结果存到表B对应的字段,即sum(salary1)-->b.tongji1
      

  2.   

    是我表达差了.传统的asp编程应该这样写,希望大家明白.
    set rs=server.createobject("Adodb.Recordset")
    sql="select distinct bdepart from A where erji='t' order by bdepartpid"
    rs.open sql,conn,1,1
    while not rs.eof    set rs2=server.createobject("Adodb.RecordSet")
        sql2="select sum(salary1) as salary1 from A where bdepart='"&rs(bdepart)&"'"
        rs2.open sql2,conn,1,1
        
          sql3="insert into b set tongji1=rs2("salary1") where bdepart='"&rs(bdepart)&"'"
          conn.execute(sql3)
        
        rs2.close
        set rs2=nothingrs.movenext
    next
    rs.close
    set rs=nothing
      

  3.   

    select   max(decode(id,1,name))   f1,max(decode(id,2,name))f2,max(decode(id,3,name))f3,max(decode(id,4,name))f4   
      from   t_test   
      union   all   
      select   to_char(max(decode(id,1,id)))   f1,to_char(max(decode(id,2,id)))f2,to_char(max(decode(id,3,id)))f3,to_char(max(decode(id,4,id)))f4   
      from   t_test   
    我也没试过,是在别的地方找的,你可以试试
      

  4.   

    其实就是想点击button后运行程序,程序的功能就是从A表提取汇总数到B表(不是全取)就是这么简单.希望 有代码参考.