http://expert.csdn.net/Expert/topic/1827/1827186.xml?temp=.5150873
工资表 aa
-----------------------------------------------
no //工号
salary //工资
month //月
year //年人员表 bb
-----------------------------------------------
no //工号
depart //部门代码部门表 cc
-----------------------------------------------
depname //部门名
depart //部门代码
_______________________________________________
要求:
给出的是******部门名*******
通过部门名=>得到部门代号
通过部门代号=>得到所有的在这个部门的人员
最后把这些人员的历年的平均工资得出.
_______________________________________________
工资表 aa
-----------------------------------------------
no //工号
salary //工资
month //月
year //年人员表 bb
-----------------------------------------------
no //工号
depart //部门代码部门表 cc
-----------------------------------------------
depname //部门名
depart //部门代码
_______________________________________________
要求:
给出的是******部门名*******
通过部门名=>得到部门代号
通过部门代号=>得到所有的在这个部门的人员
最后把这些人员的历年的平均工资得出.
_______________________________________________
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
,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
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'中
"FROM Salary INNER JOIN Person " & _
"ON Person.No=Salary.NO "
select no 前要指定來源於那個資料表,因為person和salary兩表中都有字段no,要加以區分
我在mysql数据库中执行这样一句没有问题
可是在这里就出现这样的错误
555555,郁闷!
你用select salary.no from salary left outer join person on salary.no=person.no試試
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
" 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
晕了,这样竟然没有错
但是没有数据
如何得到数据呢
Set Data1 = New ADODB.Recordset
Set Data2 = New ADODB.Recordset
重復定義外,看不出有任何問題.
这个的问题改成4.0就能运行了