关于在vba中运行sql联合查询语句的问题?
Private Sub 查询_Click()Dim strSQL As String
Dim chaxun As QueryDef
strSQL = "SELECT 成绩表.学校, 成绩表.班级, Count(成绩表.姓名) AS 人数, Sum(成绩表.数学) AS 数学, Sum(成绩表.语文) AS 语文, Sum(成绩表.英语) AS 英语 FROM 成绩表
GROUP BY 成绩表.学校, 成绩表.班级
UNION All SELECT 成绩表.学校 & "合计" as 学校, "" AS 班级, Count(成绩表.姓名) AS 人数, Sum(成绩表.数学) AS 数学, Sum(成绩表.语文) AS 语文 , Sum(成绩表.英语) AS 英语
FROM 成绩表
GROUP BY 成绩表.学校
UNION ALL SELECT "学校总计" AS 学校, "" AS 班级, Count(成绩表.姓名) AS 人数, Sum(成绩表.数学) AS 数学, Sum(成绩表.语文) AS 语文, Sum(成绩表.英语) AS 英语
FROM 成绩表
ORDER BY 学校, 班级;"
Set chaxun = CurrentDb.CreateQueryDef("linshi-jichu", strSQL)
DoCmd.OpenQuery chaxun.Name
-----------------------------------------
请问上面这段代码写成下面这样 不加联合查询 能运行成功 但怎么写才能让上面的那段有联合查询的代码段能正确的运行?
-----------------------------------------
Private Sub 查询_Click()
Dim strSQL As String
Dim chaxun As QueryDef
strSQL = "SELECT 成绩表.学校, 成绩表.班级, Count(成绩表.姓名) AS 人数, Sum(成绩表.数学) AS 数学, Sum(成绩表.语文) AS 语文, Sum(成绩表.英语) AS 英语 FROM 成绩表
GROUP BY 成绩表.学校, 成绩表.班级"
Set chaxun = CurrentDb.CreateQueryDef("linshi-jichu", strSQL)
DoCmd.OpenQuery chaxun.Name
------------------------------------------