zoukankan      html  css  js  c++  java
  • 处理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();//在关联分组
  • 相关阅读:
    iOS基础
    iOS基础 ----- 内存管理
    NSAttributedString 的一些基本用法
    node安装使用
    docker常用命令
    docker lnmp
    easy-wechat
    composer
    center7系统搭建lnmp
    xammp环境配置
  • 原文地址:https://www.cnblogs.com/qxandxt/p/12836666.html
Copyright © 2011-2022 走看看