首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

子查询时的一点有关问题,帮帮忙吧

2012-12-21 
求助:子查询时的一点问题,帮帮忙吧!数据:R表中:NameMatchEnglishC#SQLJAVAMonthPer1001828384909111100190

求助:子查询时的一点问题,帮帮忙吧!
数据:R表中:
    Name   Match   English   C#   SQL   JAVA   Month   Per 
   1001     82       83      84   90     91     1      1
   1001     90       92      94   88     82     2      1
   1001     78       77      88   90     91     3      1
   (1001这位同学参加了1月份、2月份、3月份的考试,其他月份的考试没有参加)
 
   1002     66       87      98   67     90     1      1
   1002     82       83      84   90     91     2      1
   1002     90       92      94   88     82     3      1
   (1002这位同学参加了1月份、2月份、3月份的考试,其他月份的考试没有参加)
 
   1003     78       77      88   90     91     3      1
   1003     66       87      98   67     90     4      2
   1003     82       83      84   90     91     5      2
   1003     90       92      94   88     82     6      2
   (1003这位同学参加了3月份、4月份、5月份的考试、6月份的考试,其他月份的考试没有参加)
 
   1004     78       77      88   90     91     4      2
   1004     66       87      98   67     90     5      2
   1004     82       83      84   90     91     6      2
   (1004这位同学参加了4月份、5月份、5月份的考试,其他月份的考试没有参加)


问题:根据Per进行Group by Per将各科成绩相加,但是还要求查询出属于哪个月份,我写了一段,但是有错误:select Month,Sum(Match),Sum(English),Sum(SQL),Sum(C#),Sum(Java) Gruop By Per 出错了,它提示:Month,因为该列没有包含在聚合函数或 GROUP BY 子句中,请问怎么改正?


 
[最优解释]
select Month,Sum(Match),Sum(English),Sum(SQL),Sum(C#),Sum(Java) Gruop By Month,per
[其他解释]


select Month,Sum(Match),Sum(English),Sum(SQL),Sum(C#),Sum(Java) Gruop By Month,per

--除了聚合函数以外的其他列,都要放在group by之后

[其他解释]

select Month,Sum(Match),Sum(English),Sum(SQL),Sum(C#),Sum(Java) from R with(nolock) Gruop By Per,Month

[其他解释]
select stuff((Select ','+Month from tb Where per=t.per group by Month Order by Month for xml path('')),1,1,'') As Month,Sum(Match),Sum(English),Sum(SQL),Sum(C#),Sum(Java) From R as t Gruop By per
[其他解释]
该回复于2012-11-28 15:09:31被管理员删除
[其他解释]
感谢大家!可是分数有限,只能平分了,谢谢了!

热点排行