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();//在关联分组
  • 相关阅读:
    Makefile学习
    Tmux使用
    Linux进程管理学习资料
    Linux内存管理学习资料
    Python常用的软件包
    Docker 学习
    Intel处理器技术文档
    Firefly-RK3399笔记
    Linux Kernel API
    ARM 技术文档
  • 原文地址:https://www.cnblogs.com/qxandxt/p/12836666.html
Copyright © 2011-2022 走看看