怎么实现以下情况:
表1
xm  cj
hys 20
hgs 30
hys 20
hys 50
hgs 30
用一条sql语句得到:xm  cj
                 hys  110
                 hgs  60
                 合计 170

解决方案 »

  1.   

    不知access支不支持这么复杂的SQL语句,而且不大清楚你的输出要求.
      

  2.   

    用sum()得到总和,用Group by分组,在用Union联合即可:
    "select xm,sum(cj) as cj from 表1 group by xm union select '' as xm ,sum(cj) as cj from 表1"
      

  3.   

    update 表
    set cj=
    case 
      when xm="hys" 
      then sum(xm)
      when xm="hgs"
      then sum(xm)
    end'没装SQL你试下
      

  4.   

    '在vb里用ado怎样实现:
    '工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)
    Private Sub Form_Load()
        Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
        cn.CursorLocation = adUseClient
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Test.mdb;User Id=admin;Password=;"
        rs.Open "select xm,sum(cj) as cj from 表1 group by xm union select '' as xm ,sum(cj) as cj from 表1", cn, adOpenDynamic, adLockOptimistic
        Set DataGrid1.DataSource = rs
    End Sub
      

  5.   

    select xm,sum(cj) as cj from 表1 group by xm union select '合計' as xm ,sum(cj) as cj from 表1修改faysky2()的。