首页 > 其他 > 详细

group by 与 order by 一起使用的时候

时间:2017-02-02 17:31:07      阅读:249      评论:0      收藏:0      [点我收藏+]

select 后面的列+order by 后面的列 
必须在group by 里面

也就是说 select 和 order by 后面的列是 group by 列的子集

而 select 和 order by 之间是没有什么瓜葛的。

 

SELECT [col1] ,[col2],MAX([col3]) FROM [tb] GROUP BY [col1] ,[col2]  ORDER BY [col1] ,[col2] ,MAX([col3])
SELECT [col1] ,[col2],MAX([col3]) AS  [col3] FROM [tb] GROUP BY [col1] ,[col2]  ORDER BY [col1] ,[col2] ,[col3]
SELECT [col1] ,[col2] FROM [tb] GROUP BY [col1] ,[col2] ,[col3] ORDER BY [col1] ,[col2] ,[col3]
select [TYPE],LAST_VERSION,REMARK FROM SMTSOPVersionInfo WHERE 
SOP=N" + this.SOP.Value + "group by [TYPE],LAST_VERSION,REMARK order by LAST_VERSION;

 

group by 与 order by 一起使用的时候

原文:http://www.cnblogs.com/vichin/p/6361314.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!