|
看到了你的问题,直接用excel不太容易实现,
感觉用数据库比较好,界面可以用excel,数据库是sqlite
上个附件你可以参考一下,只是一个简单的演示,提供一个思路吧。
Sub 建库建表()
Dim cnn As New cConnection
Dim rs As New cRecordset
Dim sql$
cnn.CreateNewDB ThisWorkbook.Path & "\递归.db", "1"
cnn.OpenDB ThisWorkbook.Path & "\递归.db", "1"
sql = "CREATE TABLE T1(ID INTEGER PRIMARY KEY,姓名,职务,父id,业绩)"
cnn.Execute sql
Set cnn = Nothing
End Sub
新增数据语句
Private Sub CommandButton10_Click()
If Me.TextBox1 = "" Then Exit Sub
Dim cnn As New cConnection, M%, j%
Dim rs As New cRecordset, sql$
cnn.OpenDB ThisWorkbook.Path & "\递归.db", "1"
sql = Me.TextBox1
Me.VSFlexGrid1.Clear 1, 1
If UCase(Left(sql, 1)) = "W" Then
Me.VSFlexGrid1.Clear
rs.OpenRecordset sql, cnn, True
Me.VSFlexGrid1.Rows = rs.RecordCount + 1
For j = 0 To rs.Fields.Count - 1
Me.VSFlexGrid1.TextMatrix(0, j + 1) = rs.Fields(j).Name
Next
Do While Not rs.EOF
M = M + 1
For j = 0 To rs.Fields.Count - 1
Me.VSFlexGrid1.TextMatrix(M, j + 1) = rs.Fields(j)
Next
rs.MoveNext
Loop
Else
cnn.Execute (sql)
Call UserForm_Initialize
End If
Set rs = Nothing
Set cnn = Nothing
End Sub
递归查询语句
with recursive re as
(select * from t1 where 姓名= 'A' union all
select T1.* from re INNER join T1 on re.id= t1.父id)
select * from re
简单演示一下。
分为4级(经理、主管、员工1级,员工2级)
为了看的更清楚,按照姓名来分组,比如 经理的名字是A ,则属于他这一组的都是A.....
递归.rar
(25.27 KB, 下载次数: 59)
|
评分
-
1
查看全部评分
-
|