如下表   名称                   专业                 人数
  一团                    通信                   30
  二团                    通信                   20
  一团                    炮兵                   20
  一团                    气象                   40
  
怎样写一条语句 把所有一团各专业人数综合求出来。

解决方案 »

  1.   

    怎样写一条语句 把所有一团各专业人数综合求出来。?
    select 名称,专业,人数 from table where 名称='一团'
      

  2.   

    select sum(人数) from table where 名称='一团'    or 
    select 专业,sum(人数) from table where 名称='一团' group by 专业
    我知道你的意思所以写了两个仅参考
      

  3.   

    多列几条表的数据?
    因为团和专业不重复,所以就没有加group by
      

  4.   

    select sum(人数) from table where 名称='一团' 
    这样就可以了吧。
    ------------------------------------
    体验速度,体验CSDN新版论坛助手:http://community.csdn.net/Expert/TopicView.asp?id=3108679
      

  5.   

    select sum(人数) from table where 名称='一团' 怎么接受这个返回值呢??
    这样写可以么?
    dim x as interger
     select sum(人数)as x from table where 名称='一团' 
      

  6.   

    rs.open "select sum(人数)as x from table where 名称='一团' ",conn,1,3
    msgbox rs.fields("x")
      

  7.   

    select count(人数)from 表 where 团名= ‘一团’
      

  8.   

    他说的是‘各专业人数 ’  我认为 先对专业进行查询 建立一个动态数组 然后用循环的方式进行查询这样就可得到各专业的人数了                  法子比较苯效率方面成问题!!!!!!!!!!!!!!!!!!!!!!!!!!!有待讨论
       Dim str_w() As String
       dim I_count,i  as Integer ......
       zr.open ""SELECT DISTINCT [专业] from [企业资料]",conn,1,3
       If zr.RecordCount > 0 Then
                    For i = 1 To zr.RecordCount
                    
                        I_count = I_count + 1
                        ReDim Preserve str_w(I_count)
                        str_w(I_count) = zr.Fields(0).Value
                        If Not zr.EOF() Then zr.MoveNext
                    Next i
        .......
        for i=1 to I_count
            set zr=nothing
            set zr=new adodb.recordset        zr.open "select sum(人数) as w from [表] where [名称]='一团' and [专业]='" & str_w(i) &"'" ,conn,1,3
            msgbox zr.fields("w")
         next
    ............
     
      

  9.   

    "龙卷风V2.0--再战江湖" 的写法应该是最合理的
    select 专业,sum(人数)  from table where 名称='一团' group by 专业
    不能用count,count只是统计满足条件的记录数。