温馨提示×

mysql如何使用分组排序

九三
159
2020-12-19 13:03:57
栏目: 云计算
亿速云mysql数据库,读写分离,安全稳定,弹性扩容,低至0.3元/天!! 点击查看>>

mysql如何使用分组排序

mysql中使用分组排序的方法

在mysql中使用order by方法实现分组排序

实现方法如下:

select id, (@rowno := @rowno + 1) as rank,

score,

(C.end_time - C.start_time) as timeConsuming,

start_time,

real_name,

tel,

expiry_code

from (SELECT *

FROM (select *

from t_q_order B

where B.score > 0

and B.tel IS NOT NULL

order by B.score desc,

(B.end_time - B.start_time) asc,

B.start_time asc) as A

group by A.tel

ORDER BY A.score desc,

(A.end_time - A.start_time) asc,

A.start_time asc)

as C,

(select @rowno := 0) t

where (C.end_time - C.start_time) > 5 limit 0,50;

亿速云「云数据库 MySQL」免部署即开即用,比自行安装部署数据库高出1倍以上的性能,双节点冗余防止单节点故障,数据自动定期备份随时恢复。点击查看>>

推荐阅读:MySQL关联查询中如何使用分组和排序

0