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

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

        <bdo id='Nuurt'></bdo><ul id='Nuurt'></ul>

      1. SQL查询以获取与另一列的MAX值对应的列值?

        SQL Query to get column values that correspond with MAX value of another column?(SQL查询以获取与另一列的MAX值对应的列值?)
          <tbody id='p2QDz'></tbody>

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

            <bdo id='p2QDz'></bdo><ul id='p2QDz'></ul>
          • <tfoot id='p2QDz'></tfoot>
          • <small id='p2QDz'></small><noframes id='p2QDz'>

                  本文介绍了SQL查询以获取与另一列的MAX值对应的列值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  好的,这是我的查询:

                  SELECT
                    video_category,
                    video_url,
                    video_date,
                    video_title,
                    short_description,
                    MAX(video_id) 
                  FROM
                    videos
                  GROUP BY
                    video_category
                  

                  当它提取数据时,我得到了 video_id 的正确行,但它为其他类别提取了每个类别的第一行.因此,当我获得类别 1 的 video_id 的最大结果时,我获得了最大 ID,但表格中的第一行是 url、日期、标题和描述.

                  When it pulls the data, I get the correct row for the video_id, but it pulls the first row for each category for the others. So when I get the max result for the video_id of category 1, I get the max ID, but the first row in the table for the url, date, title, and description.

                  我怎样才能让它拉出与最大 ID 结果相对应的其他列?

                  How can I have it pull the other columns that correspond with the max ID result?

                  固定.

                  SELECT
                      *
                  FROM
                      videos
                  WHERE
                      video_id IN
                      (
                          SELECT
                              DISTINCT
                              MAX(video_id)
                          FROM
                              videos
                          GROUP BY
                              video_category
                      ) 
                  ORDER BY
                      video_category ASC
                  

                  推荐答案

                  我会尝试这样的事情:

                  SELECT
                     s.video_id
                     ,s.video_category
                     ,s.video_url
                     ,s.video_date
                     ,s.video_title
                     ,short_description
                  FROM videos s
                     JOIN (SELECT MAX(video_id) AS id FROM videos GROUP BY video_category) max
                        ON s.video_id = max.id
                  

                  这比您自己的解决方案要快得多

                  which is quite faster that your own solution

                  这篇关于SQL查询以获取与另一列的MAX值对应的列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bogus foreign key constraint fail(虚假外键约束失败)
                  how to get last insert id after insert query in codeigniter active record(如何在codeigniter活动记录中插入查询后获取最后一个插入ID)
                  Force InnoDB to recheck foreign keys on a table/tables?(强制 InnoDB 重新检查表/表上的外键?)
                  How to auto generate migrations with Sequelize CLI from Sequelize models?(如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?)
                  Clear MySQL query cache without restarting server(无需重启服务器即可清除 MySQL 查询缓存)
                  ALTER TABLE to add a composite primary key(ALTER TABLE 添加复合主键)

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

                      <tbody id='zirzt'></tbody>
                    <legend id='zirzt'><style id='zirzt'><dir id='zirzt'><q id='zirzt'></q></dir></style></legend>
                      <bdo id='zirzt'></bdo><ul id='zirzt'></ul>

                          <tfoot id='zirzt'></tfoot>

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