我有一个学生成绩的access数据库,现在我要做一个学生成绩的年组大榜.我用了这样一个语句:
SELECT a.stuid as 学号,a.stuname as 姓名,a.StuClass as 班级,a.score as 语文,b.score as 数学 ,c.score as 英语,d.score as 物理,e.score as 化学,f.score as 生物,(a.score + b.score + c.score + d.score+e.score) as 总分
from( ((((AYW_20070719_Score as a
left join bsx_20070719_Score as b on a.stuid = b.stuid )
left join cyy_20070719_Score as c on a.stuid = c.stuid)
left join dwl_20070719_Score as d on a.stuid = d.stuid)
left join ehx_20070719_Score as e on a.stuid = e.stuid)
left join fsw_20070719_Score as f on a.stuid = f.stuid)
order by (a.score + b.score + c.score + d.score+e.score) desc暂时我只能实现这样一个表:
学号 姓名 班级 语文 数学 英语 物理 化学 生物 总分(降序)但是现在的要求改变了,需要的格式是:
学号 姓名 班级 语文 语文的班排名 语文的年组排名 数学 .....类推我想请大家给写意见,怎么才能实现后来这个表啊.
SELECT a.stuid as 学号,a.stuname as 姓名,a.StuClass as 班级,a.score as 语文,b.score as 数学 ,c.score as 英语,d.score as 物理,e.score as 化学,f.score as 生物,(a.score + b.score + c.score + d.score+e.score) as 总分
from( ((((AYW_20070719_Score as a
left join bsx_20070719_Score as b on a.stuid = b.stuid )
left join cyy_20070719_Score as c on a.stuid = c.stuid)
left join dwl_20070719_Score as d on a.stuid = d.stuid)
left join ehx_20070719_Score as e on a.stuid = e.stuid)
left join fsw_20070719_Score as f on a.stuid = f.stuid)
order by (a.score + b.score + c.score + d.score+e.score) desc暂时我只能实现这样一个表:
学号 姓名 班级 语文 数学 英语 物理 化学 生物 总分(降序)但是现在的要求改变了,需要的格式是:
学号 姓名 班级 语文 语文的班排名 语文的年组排名 数学 .....类推我想请大家给写意见,怎么才能实现后来这个表啊.
'*********************************************************
'* 名称:ExporToExcel
'* 功能:导出数据到EXCEL
'* 用法:ExporToExcel(sql查询字符串)
'*********************************************************
Dim Rs_Data As New ADODB.Recordset
Dim Irowcount As Integer
Dim Icolcount As Integer
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlQuery As Excel.QueryTable
With Rs_Data
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = Cn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Source = strOpen
.Open
End With
With Rs_Data
If .RecordCount < 1 Then
MsgBox ("没有记录!")
Exit Function
End If
'记录总数
Irowcount = .RecordCount
'字段总数
Icolcount = .Fields.Count
End With
Set xlApp = CreateObject("Excel.Application")
Set xlBook = Nothing
Set xlSheet = Nothing
Set xlBook = xlApp.Workbooks().Add
Set xlSheet = xlBook.Worksheets("sheet1")
xlApp.Visible = True
'添加查询语句,导入EXCEL数据
Set xlQuery = xlSheet.QueryTables.Add(Rs_Data, xlSheet.Range("a1"))
With xlQuery
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
End With
xlQuery.FieldNames = True '显示字段名
xlQuery.Refresh
With xlSheet
.Range(.Cells(1, 1), .Cells(1, Icolcount)).Font.Name = "黑体"
'设标题为黑体字
.Range(.Cells(1, 1), .Cells(1, Icolcount)).Font.Bold = True
'标题字体加粗
.Range(.Cells(1, 1), .Cells(Irowcount + 1, Icolcount)).Borders.LineStyle = xlContinuous
'设表格边框样式
End With
With xlSheet.PageSetup
.LeftHeader = "" & Chr(10) & "&""楷体_GB2312,常规""&10公司名称:" ' & Gsmc
.CenterHeader = "&""楷体_GB2312,常规""公司人员情况表&""宋体,常规""" & Chr(10) & "&""楷体_GB2312,常规""&10日 期:"
.RightHeader = "" & Chr(10) & "&""楷体_GB2312,常规""&10单位:"
.LeftFooter = "&""楷体_GB2312,常规""&10制表人:"
.CenterFooter = "&""楷体_GB2312,常规""&10制表日期:"
.RightFooter = "&""楷体_GB2312,常规""&10第&P页 共&N页"
End With
xlApp.Application.Visible = True
Set xlApp = Nothing '"交还控制给Excel
Set xlBook = Nothing
Set xlSheet = NothingEnd Function
VB 程序里先从Access中取出数据,放在rs记录集中。
然后使用excel的com对象打开一个excel文件,在调excel对象中的方法向excel里写数据,具体写成什么格式当然就随你了。
但是只能实现按总分排名....
不过我现在需要做成学号 姓名 班级 语文 语文的班排名 语文的年组排名 数学 .....类推这个格式,我现在主要不会的就是 如何实现在按照总分排名以后,再显示他的单科成绩在本班的排名、在年组中的排名 比如一个学生 总分排第一 但他的语文成绩在班级排第2 ,在年组排20那么我应该怎么去实现呢。应为我用的是ACCESS数据库,所以不能创建视图。