http://expert.csdn.net/Expert/topic/1827/1827186.xml?temp=.5150873
工资表 aa
-----------------------------------------------
no //工号
salary //工资
month //月
year //年人员表 bb
-----------------------------------------------
no //工号
depart //部门代码部门表 cc
-----------------------------------------------
depname //部门名
depart //部门代码
_______________________________________________
要求:
给出的是******部门名*******
通过部门名=>得到部门代号
通过部门代号=>得到所有的在这个部门的人员
最后把这些人员的历年的平均工资得出.
_______________________________________________

解决方案 »

  1.   

    你所指的歷年平均工資是否是數年來平均每年的工資?
    select 工资表.no,sum(salary)/(結束年-起始年) as 平均工資 from 工资表 inner join 人員表 on 工资表.no=人員表.no inner join 部门表 on 人員表.depart=部门表.depart where (year between '起始年' and '結束年') and 部门表.depname='部門名'  group by 工资表.no
      

  2.   

    select 工资表.no,工资表.year
    ,sum(salary)/12 as 平均工資 from 工资表 inner join 人員表 on 工资表.no=人員表.no inner join 部门表 on 人員表.depart=部门表.depart where (year between '起始年' and '結束年') and 部门表.depname='部門名'  group by 工资表.no,工资表.year
      

  3.   

    -------------------------------------
      Set Data2 = New ADODB.Recordset
      sql = "SELECT no " & _
            "FROM Salary INNER JOIN Person " & _
            "ON Person.No=Salary.NO "
      Data2.open sql, DB
    ------------------------------------
    我在使用查询时出现这样的问题:
    实时错误'-2147217900(80040e14)'
    '.','!',or'()'在使用时非法.在查询表达式
    'Person.No=Salary.NO'中
      

  4.   

    sql = "SELECT Salary.no " & _
            "FROM Salary INNER JOIN Person " & _
            "ON Person.No=Salary.NO "
    select no 前要指定來源於那個資料表,因為person和salary兩表中都有字段no,要加以區分
      

  5.   

    select salary.no from salary inner join person on salary.no=person.no
    我在mysql数据库中执行这样一句没有问题
    可是在这里就出现这样的错误
    555555,郁闷!
      

  6.   

    樓主,從語法來看是真的沒問題.不知道是不是有錯誤資料.
    你用select salary.no from salary left outer join person on salary.no=person.no試試
      

  7.   


    Private Sub Command1_Click()
    Dim DB As New ADODB.Connection
    Dim Data1 As New ADODB.Recordset
    Dim Data2 As New ADODB.Recordset
    Dim strCnn As String
    Dim sql As String
    Dim num As Integer
    Dim a() As String
    Dim i As Integer
    ' 打开链接,数据库在此程序的目录下
        strCnn = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
            "Data Source='" & App.Path & "\Employee.mdb'"
        Set DB = New ADODB.Connection
        DB.open strCnn
        
      '取得记录集data1
      Set Data1 = New ADODB.Recordset
      Data1.open "select Department,DepName from Department", DB
        For i = 0 To Data1.RecordCount - 1
            a(i) = Data1.Fields(i)
            MsgBox (a(i))
        Next
      '取得记录集data2
      Set Data2 = New ADODB.Recordset
    sql = "SELECT Salary.no " & _
            "FROM Salary INNER JOIN Person " & _
            "ON Person.No=Salary.NO "
      Data2.open sql, DB
    End Sub
      

  8.   

    sql = "SELECT salary.*, person.*" & _
            " FROM salary inner JOIN person ON salary.[NO]=person.[No]"
           'sql = "SELECT Department from Department where DepName='" & DBCombo1.Text & "'"
            MsgBox sql
            Data2.open sql, DB
    晕了,这样竟然没有错
    但是没有数据
    如何得到数据呢
      

  9.   

    这样链接后和没链接表person一样,不管person有没有数据一很搜出来,TNN的
      

  10.   

    上面的代碼除了
    Set Data1 = New ADODB.Recordset
    Set Data2 = New ADODB.Recordset
    重復定義外,看不出有任何問題.
      

  11.   

    能运行了,原来是strCnn = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
    这个的问题改成4.0就能运行了