在我的student表中有sno,sname,sdept,sage
我直接这样写order by后面的列并没有在select后面答案是对的
select sno,sname from student order by sage desc; //没有问题
但是我用加上group by后,按照它报的错,order by后面的列必须要是在group by中出现的,这是为什么呢?
select sname,sdept,ssex from student group by sname,sdept,ssex having sdept ='MA' and ssex = '女' order by sage; //有错
select sname,sdept,ssex from student group by sname,sdept,ssex having sdept ='MA' and ssex = '女' order by sname; //这样也没问题
Sql group by与order by 后面的列的问题
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
oyljerry 2016-04-10 07:12关注这是group by的语法,分组了以后,order需要是分组的列
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报