学生表 任务表 课堂成绩表
student taskScore classScore
学生表 列 id name stuGrade stuClass
任务表 列 id stuId(与学生表ID对应) score isExgam(值为0表示一般任务,为1表示是期末考试)
课堂成绩表 列 id stuId(与学生表ID对应) score
我现在想一次查询成这样的形式
姓名 任务平均分 课堂平均分 期末成绩分
id name tScore cScore eScore
我的select语句是这样的
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 南月
-- Create date: 2011-2-12 9:27:10
-- Description: 根据班级查询成绩汇总信息
-- =============================================
create PROCEDURE [dbo].[ScoreTotal]
@stuGrade int,@stuClass int
AS
BEGIN
select s.id ,s.[name],s.[group] stuGroup,s.seat,s.grade stuGrade,s.stuClass,
(select avg(score) from classScore cs where cs.stuId=s.id) as cScore,
(select avg(score) from taskScore ts where ts.stuId=s.id and ts.isExgam=0) as tScore,
(select score from taskScore ts where ts.stuId=s.id and ts.isExgam>0) as eScore,
from student s where s.grade=@stuGrade and s.stuClass=@stuClass
order by s.[group],s.seat
END
但是报14行 from 附近有错
7 个解决方案
#1
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 南月
-- Create date: 2011-2-12 9:27:10
-- Description: 根据班级查询成绩汇总信息
-- =============================================
create PROCEDURE [dbo].[ScoreTotal]
@stuGrade int,@stuClass int
AS
BEGIN
select s.id ,s.[name],s.[group] stuGroup,s.seat,s.grade stuGrade,s.stuClass,
(select avg(score) from classScore cs where cs.stuId=s.id) as cScore,
(select avg(score) from taskScore ts where ts.stuId=s.id and ts.isExgam=0) as tScore,
(select score from taskScore ts where ts.stuId=s.id and ts.isExgam>0) as eScore ,
from student s where s.grade=@stuGrade and s.stuClass=@stuClass
order by s.[group],s.seat
END
还是逗号
#2
select * from 表A A,表B B,表C C where A.字段=B.字段 and 继续你的条件
#3
就是加上条件就行了select * from 表A A,表B B,表C C where A.字段=B.字段 and 继续你的条件。
#4
对啊,这会儿,我也测出来了,多了个逗号,谢谢你们!
#5
那里多了一个逗号set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 南月
-- Create date: 2011-2-12 9:27:10
-- Description: 根据班级查询成绩汇总信息
-- =============================================
create PROCEDURE [dbo].[ScoreTotal]
@stuGrade int,@stuClass int
AS
BEGIN
select s.id ,s.[name],s.[group] stuGroup,s.seat,s.grade stuGrade,s.stuClass,
(select avg(score) from classScore cs where cs.stuId=s.id) as cScore,
(select avg(score) from taskScore ts where ts.stuId=s.id and ts.isExgam=0) as tScore,
(select score from taskScore ts where ts.stuId=s.id and ts.isExgam>0) as eScore ,
from student s where s.grade=@stuGrade and s.stuClass=@stuClass
order by s.[group],s.seat
END
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 南月
-- Create date: 2011-2-12 9:27:10
-- Description: 根据班级查询成绩汇总信息
-- =============================================
create PROCEDURE [dbo].[ScoreTotal]
@stuGrade int,@stuClass int
AS
BEGIN
select s.id ,s.[name],s.[group] stuGroup,s.seat,s.grade stuGrade,s.stuClass,
(select avg(score) from classScore cs where cs.stuId=s.id) as cScore,
(select avg(score) from taskScore ts where ts.stuId=s.id and ts.isExgam=0) as tScore,
(select score from taskScore ts where ts.stuId=s.id and ts.isExgam>0) as eScore ,
from student s where s.grade=@stuGrade and s.stuClass=@stuClass
order by s.[group],s.seat
END
#6
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 南月
-- Create date: 2011-2-12 9:27:10
-- Description: 根据班级查询成绩汇总信息
-- =============================================
create PROCEDURE [dbo].[ScoreTotal]
@stuGrade int,@stuClass int
AS
BEGIN
select s.id ,s.[name],s.[group] stuGroup,s.seat,s.grade stuGrade,s.stuClass,
(select avg(score) from classScore cs where cs.stuId=s.id) as cScore,
(select avg(score) from taskScore ts where ts.stuId=s.id and ts.isExgam=0) as tScore,
(select score from taskScore ts where ts.stuId=s.id and ts.isExgam>0) as eScore,
from student s where s.grade=@stuGrade and s.stuClass=@stuClass
order by s.[group],s.seat
END
#7
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 南月
-- Create date: 2011-2-12 9:27:10
-- Description: 根据班级查询成绩汇总信息
-- =============================================
create PROCEDURE [dbo].[ScoreTotal]
@stuGrade int,@stuClass int
AS
BEGIN
select s.id ,s.[name],s.[group] stuGroup,s.seat,s.grade stuGrade,s.stuClass,
(select avg(score) from classScore cs where cs.stuId=s.id) as cScore,
(select avg(score) from taskScore ts where ts.stuId=s.id and ts.isExgam=0) as tScore,
(select score from taskScore ts where ts.stuId=s.id and ts.isExgam>0) as
from student s where s.grade=@stuGrade and s.stuClass=@stuClass
order by s.[group],s.seat
END
#1
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 南月
-- Create date: 2011-2-12 9:27:10
-- Description: 根据班级查询成绩汇总信息
-- =============================================
create PROCEDURE [dbo].[ScoreTotal]
@stuGrade int,@stuClass int
AS
BEGIN
select s.id ,s.[name],s.[group] stuGroup,s.seat,s.grade stuGrade,s.stuClass,
(select avg(score) from classScore cs where cs.stuId=s.id) as cScore,
(select avg(score) from taskScore ts where ts.stuId=s.id and ts.isExgam=0) as tScore,
(select score from taskScore ts where ts.stuId=s.id and ts.isExgam>0) as eScore ,
from student s where s.grade=@stuGrade and s.stuClass=@stuClass
order by s.[group],s.seat
END
还是逗号
#2
select * from 表A A,表B B,表C C where A.字段=B.字段 and 继续你的条件
#3
就是加上条件就行了select * from 表A A,表B B,表C C where A.字段=B.字段 and 继续你的条件。
#4
对啊,这会儿,我也测出来了,多了个逗号,谢谢你们!
#5
那里多了一个逗号set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 南月
-- Create date: 2011-2-12 9:27:10
-- Description: 根据班级查询成绩汇总信息
-- =============================================
create PROCEDURE [dbo].[ScoreTotal]
@stuGrade int,@stuClass int
AS
BEGIN
select s.id ,s.[name],s.[group] stuGroup,s.seat,s.grade stuGrade,s.stuClass,
(select avg(score) from classScore cs where cs.stuId=s.id) as cScore,
(select avg(score) from taskScore ts where ts.stuId=s.id and ts.isExgam=0) as tScore,
(select score from taskScore ts where ts.stuId=s.id and ts.isExgam>0) as eScore ,
from student s where s.grade=@stuGrade and s.stuClass=@stuClass
order by s.[group],s.seat
END
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 南月
-- Create date: 2011-2-12 9:27:10
-- Description: 根据班级查询成绩汇总信息
-- =============================================
create PROCEDURE [dbo].[ScoreTotal]
@stuGrade int,@stuClass int
AS
BEGIN
select s.id ,s.[name],s.[group] stuGroup,s.seat,s.grade stuGrade,s.stuClass,
(select avg(score) from classScore cs where cs.stuId=s.id) as cScore,
(select avg(score) from taskScore ts where ts.stuId=s.id and ts.isExgam=0) as tScore,
(select score from taskScore ts where ts.stuId=s.id and ts.isExgam>0) as eScore ,
from student s where s.grade=@stuGrade and s.stuClass=@stuClass
order by s.[group],s.seat
END
#6
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 南月
-- Create date: 2011-2-12 9:27:10
-- Description: 根据班级查询成绩汇总信息
-- =============================================
create PROCEDURE [dbo].[ScoreTotal]
@stuGrade int,@stuClass int
AS
BEGIN
select s.id ,s.[name],s.[group] stuGroup,s.seat,s.grade stuGrade,s.stuClass,
(select avg(score) from classScore cs where cs.stuId=s.id) as cScore,
(select avg(score) from taskScore ts where ts.stuId=s.id and ts.isExgam=0) as tScore,
(select score from taskScore ts where ts.stuId=s.id and ts.isExgam>0) as eScore,
from student s where s.grade=@stuGrade and s.stuClass=@stuClass
order by s.[group],s.seat
END
#7
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 南月
-- Create date: 2011-2-12 9:27:10
-- Description: 根据班级查询成绩汇总信息
-- =============================================
create PROCEDURE [dbo].[ScoreTotal]
@stuGrade int,@stuClass int
AS
BEGIN
select s.id ,s.[name],s.[group] stuGroup,s.seat,s.grade stuGrade,s.stuClass,
(select avg(score) from classScore cs where cs.stuId=s.id) as cScore,
(select avg(score) from taskScore ts where ts.stuId=s.id and ts.isExgam=0) as tScore,
(select score from taskScore ts where ts.stuId=s.id and ts.isExgam>0) as
from student s where s.grade=@stuGrade and s.stuClass=@stuClass
order by s.[group],s.seat
END