qxandxt

导航

处理mysql先排序在分组

--方法一,仅适用于低于5.7版本的MySql--
select * from (select * from shop order by price desc) a GROUP BY a.shop_name;

--方法二--
select * from (select * from shop order by price desc limit 999999) a GROUP BY a.shop_name;

--方法三--
select * from shop a where N > (select count(*) from shop b where b.shop_name = a.shop_name and a.price < b.price) order by a.shop_name,a.price desc;


tp框架如何处理mysql先排序在分组
$giModel = M('GroupIntegral');
$gi_table = $giModel->order('id desc')->limit('999')->buildSql();//先排序
$gi_list = $giModel->table($gi_table .'as gi')
->field('gi.*,m.username,m.mobile')
->group('gi.uid')
->join('pre_members m on m.uid = gi.uid')
->select();//在关联分组

 

posted on 2020-05-06 15:29  qxandxt  阅读(562)  评论(0编辑  收藏  举报