SQL中如何GROUP BY 所有的表中信息。
selectsastudent.*,avg(saScore.Score)fromsastudent,saScorewheresastudent.Sno=saScore.S...
select sastudent.*, avg(saScore.Score)
from sastudent,saScore
where sastudent.Sno=saScore.Sno
group by sastudent。1,sasatudent。2。。。等等
我现在这样GROUP BY需要把sastudent中的所有字段都给写出来,我现在想不用把这些写出来,也能GROUP BY。。请问有什么办法啊。。 展开
from sastudent,saScore
where sastudent.Sno=saScore.Sno
group by sastudent。1,sasatudent。2。。。等等
我现在这样GROUP BY需要把sastudent中的所有字段都给写出来,我现在想不用把这些写出来,也能GROUP BY。。请问有什么办法啊。。 展开
4个回答
展开全部
你可以使用如下写法
select sastudent.*, (select avg(a.Score) from sa_score a where a.sno = sastudent.sno)
from sastudent
select sastudent.*, (select avg(a.Score) from sa_score a where a.sno = sastudent.sno)
from sastudent
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
mysql中的话,不写group by聚集函数就是对全体数据起作用,比如:select avg(Sage) from student 就把学生表中总的平均年龄计算出来了,你可以把它用括号括起来当做一个数据来处理,外面可以是逻辑判断之类的(外面可以是in 或是 >什么的)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有办法,只能一个一个写
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
group by 的用法是:你 select 哪个字段,就要 group by 哪个字段
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询