• <small id='cqxgc'></small><noframes id='cqxgc'>

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

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

    1. <tfoot id='cqxgc'></tfoot>

        • <bdo id='cqxgc'></bdo><ul id='cqxgc'></ul>

        GROUP BY 与 MAX(DATE)

        时间:2023-07-18

        1. <small id='mr23b'></small><noframes id='mr23b'>

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

                1. 本文介绍了GROUP BY 与 MAX(DATE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在表格中列出每列火车的最新目的地(最大出发时间),forz/a>:

                  I'm trying to list the latest destination (MAX departure time) for each train in a table, for example:

                  Train    Dest      Time
                  1        HK        10:00
                  1        SH        12:00
                  1        SZ        14:00
                  2        HK        13:00
                  2        SH        09:00
                  2        SZ        07:00
                  

                  想要的结果应该是:

                  Train    Dest      Time
                  1        SZ        14:00
                  2        HK        13:00
                  

                  我试过使用

                  SELECT Train, Dest, MAX(Time)
                  FROM TrainTable
                  GROUP BY Train
                  

                  我收到了ora-00979 not a GROUP BY expression"错误,提示我必须在 group by 语句中包含Dest".但这肯定不是我想要的......

                  by I got a "ora-00979 not a GROUP BY expression" error saying that I must include 'Dest' in my group by statement. But surely that's not what I want...

                  是否可以在一行 SQL 中完成?

                  Is it possible to do it in one line of SQL?

                  推荐答案

                  您不能在结果集中包含未分组的非聚合列.如果一列火车只有一个目的地,那么只需将目的地列添加到您的 group by 子句中,否则您需要重新考虑您的查询.

                  You cannot include non-aggregated columns in your result set which are not grouped. If a train has only one destination, then just add the destination column to your group by clause, otherwise you need to rethink your query.

                  试试:

                  SELECT t.Train, t.Dest, r.MaxTime
                  FROM (
                        SELECT Train, MAX(Time) as MaxTime
                        FROM TrainTable
                        GROUP BY Train
                  ) r
                  INNER JOIN TrainTable t
                  ON t.Train = r.Train AND t.Time = r.MaxTime
                  

                  这篇关于GROUP BY 与 MAX(DATE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Oracle SQL:用另一个表中的数据更新一个表 下一篇:有没有“LIKE"的组合?和“IN"在 SQL 中?

                  相关文章

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

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

                  1. <legend id='QHDKa'><style id='QHDKa'><dir id='QHDKa'><q id='QHDKa'></q></dir></style></legend>

                      <tfoot id='QHDKa'></tfoot>