<legend id='HApku'><style id='HApku'><dir id='HApku'><q id='HApku'></q></dir></style></legend>

    1. <i id='HApku'><tr id='HApku'><dt id='HApku'><q id='HApku'><span id='HApku'><b id='HApku'><form id='HApku'><ins id='HApku'></ins><ul id='HApku'></ul><sub id='HApku'></sub></form><legend id='HApku'></legend><bdo id='HApku'><pre id='HApku'><center id='HApku'></center></pre></bdo></b><th id='HApku'></th></span></q></dt></tr></i><div id='HApku'><tfoot id='HApku'></tfoot><dl id='HApku'><fieldset id='HApku'></fieldset></dl></div>

      <small id='HApku'></small><noframes id='HApku'>

        <bdo id='HApku'></bdo><ul id='HApku'></ul>
    2. <tfoot id='HApku'></tfoot>
    3. MySQL - 获取最低值

      时间:2024-04-16

      • <legend id='M28K2'><style id='M28K2'><dir id='M28K2'><q id='M28K2'></q></dir></style></legend>

            <tbody id='M28K2'></tbody>

          <small id='M28K2'></small><noframes id='M28K2'>

        1. <tfoot id='M28K2'></tfoot>
            <i id='M28K2'><tr id='M28K2'><dt id='M28K2'><q id='M28K2'><span id='M28K2'><b id='M28K2'><form id='M28K2'><ins id='M28K2'></ins><ul id='M28K2'></ul><sub id='M28K2'></sub></form><legend id='M28K2'></legend><bdo id='M28K2'><pre id='M28K2'><center id='M28K2'></center></pre></bdo></b><th id='M28K2'></th></span></q></dt></tr></i><div id='M28K2'><tfoot id='M28K2'></tfoot><dl id='M28K2'><fieldset id='M28K2'></fieldset></dl></div>

              • <bdo id='M28K2'></bdo><ul id='M28K2'></ul>
                本文介绍了MySQL - 获取最低值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我的数据库结构包含列:id、name、value、dealer.我想为 每个 dealer 检索具有最低 value 的行.我一直在尝试使用 MIN()GROUP BY,但仍然没有解决方案.

                My database structure contains columns: id, name, value, dealer. I want to retrieve row with lowest value for each dealer. I've been trying to mess up with MIN() and GROUP BY, still - no solution.

                推荐答案

                Solution1:

                SELECT t1.* FROM your_table t1
                JOIN (
                  SELECT MIN(value) AS min_value, dealer
                  FROM your_table 
                  GROUP BY dealer
                ) AS t2 ON t1.dealer = t2.dealer AND t1.value = t2.min_value
                

                解决方案 2:

                SELECT t1.* FROM your_table t1
                LEFT JOIN your_table t2
                ON t1.dealer = t2.dealer AND t1.value > t2.value
                WHERE t2.value IS NULL
                

                这个问题非常有名,所以在Mysql的手册中有专门的页面.

                This problem is very famous, so there is a special page for this in Mysql's manual.

                检查:行保持某列的分组最大值/最小值

                这篇关于MySQL - 获取最低值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:带聚合函数的 SQL GROUP BY CASE 语句 下一篇:如何在MySQL中为每个组选择第一行?

                相关文章

                <small id='KFLsX'></small><noframes id='KFLsX'>

                • <bdo id='KFLsX'></bdo><ul id='KFLsX'></ul>
                <legend id='KFLsX'><style id='KFLsX'><dir id='KFLsX'><q id='KFLsX'></q></dir></style></legend>

                  1. <tfoot id='KFLsX'></tfoot>
                    <i id='KFLsX'><tr id='KFLsX'><dt id='KFLsX'><q id='KFLsX'><span id='KFLsX'><b id='KFLsX'><form id='KFLsX'><ins id='KFLsX'></ins><ul id='KFLsX'></ul><sub id='KFLsX'></sub></form><legend id='KFLsX'></legend><bdo id='KFLsX'><pre id='KFLsX'><center id='KFLsX'></center></pre></bdo></b><th id='KFLsX'></th></span></q></dt></tr></i><div id='KFLsX'><tfoot id='KFLsX'></tfoot><dl id='KFLsX'><fieldset id='KFLsX'></fieldset></dl></div>