开发者

MySQL, sorting before a group by

If I issue a query like this:

select c1, c2, c3
from table
group by c1;

i get distinct results for c1, but how do i sort 开发者_C百科it (e.g. c2 descending) before the group by?


select c1, c2, c3 
from (select c1, c2, c3 from table order by c2 desc) t 
group by c1;


Your question is unclear, but if you need got higher value of c2 for each c1 you may use Max

select c1, Max(c2), Max(c3)
from table
group by c1


Your query won't work as is. If I understand what you want try something closer to this:

select c1,c2,c3 from table group by c1,c2,c3 order by c1,c2 desc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜