Dim SQL As String
SQL = "SELECT DISTINCT 场区,品种,批次,year(max(日期)) as 年,month(max(日期)) as 月,0 As 公鸡,0 As 母鸡 From {生产预算} group by 场区,品种,批次"
Dim t As Table=Tables("生产预算_table3")
t.FILL(SQL,"",True)
For Each da As DataRow In t.DataTable.DataRows
Dim dr As DataRow
dr=DataTables("生产预算").Find("批次='" & da("批次") & "' and 场区='" & da("场区") & "'","日期 DESC")
If dr IsNot Nothing Then
da("公鸡")=dr("公鸡存栏")
da("母鸡")=dr("母鸡存栏")
End If
Next