<legend id='4i1vv'><style id='4i1vv'><dir id='4i1vv'><q id='4i1vv'></q></dir></style></legend>

<small id='4i1vv'></small><noframes id='4i1vv'>

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

  2. <tfoot id='4i1vv'></tfoot>

    1. 获取列具有最大值的行

      Fetch the row which has the Max value for a column(获取列具有最大值的行)
      1. <i id='NLi2R'><tr id='NLi2R'><dt id='NLi2R'><q id='NLi2R'><span id='NLi2R'><b id='NLi2R'><form id='NLi2R'><ins id='NLi2R'></ins><ul id='NLi2R'></ul><sub id='NLi2R'></sub></form><legend id='NLi2R'></legend><bdo id='NLi2R'><pre id='NLi2R'><center id='NLi2R'></center></pre></bdo></b><th id='NLi2R'></th></span></q></dt></tr></i><div id='NLi2R'><tfoot id='NLi2R'></tfoot><dl id='NLi2R'><fieldset id='NLi2R'></fieldset></dl></div>

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

          <tbody id='NLi2R'></tbody>
        • <bdo id='NLi2R'></bdo><ul id='NLi2R'></ul>

        • <tfoot id='NLi2R'></tfoot>

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

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

                问题描述

                表格:

                UserId, Value, Date.
                

                我想获取每个用户 ID 的用户 ID,最大值(日期)的值.即,具有最新日期的每个 UserId 的值.有没有办法在 SQL 中简单地做到这一点?(最好是 Oracle)

                I want to get the UserId, Value for the max(Date) for each UserId. That is, the Value for each UserId that has the latest date. Is there a way to do this simply in SQL? (Preferably Oracle)

                更新: 对任何歧义表示歉意:我需要获取所有用户 ID.但是对于每个 UserId,只有该用户具有最新日期的那一行.

                Update: Apologies for any ambiguity: I need to get ALL the UserIds. But for each UserId, only that row where that user has the latest date.

                推荐答案

                这将检索 my_date 列值等于该用户 ID 的 my_date 最大值的所有行.这可能会为 userid 检索多行,其中最大日期在多行上.

                This will retrieve all rows for which the my_date column value is equal to the maximum value of my_date for that userid. This may retrieve multiple rows for the userid where the maximum date is on multiple rows.

                select userid,
                       my_date,
                       ...
                from
                (
                select userid,
                       my_date,
                       ...
                       max(my_date) over (partition by userid) max_my_date
                from   users
                )
                where my_date = max_my_date
                

                解析函数摇滚"

                关于第一条评论......

                With regard to the first comment ...

                使用分析查询和自联接违背了分析查询的目的"

                "using analytic queries and a self-join defeats the purpose of analytic queries"

                此代码中没有自联接.相反,在包含分析函数的内联视图的结果上放置了一个谓词——这是完全不同的事情,而且完全是标准做法.

                There is no self-join in this code. There is instead a predicate placed on the result of the inline view that contains the analytic function -- a very different matter, and completely standard practice.

                Oracle 中的默认窗口是从分区的第一行到当前行"

                "The default window in Oracle is from the first row in the partition to the current one"

                windowing 子句只适用于 order by 子句.没有 order by 子句,默认不应用窗口子句,也不能显式指定.

                The windowing clause is only applicable in the presence of the order by clause. With no order by clause, no windowing clause is applied by default and none can be explicitly specified.

                代码有效.

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

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

                相关文档推荐

                Select n random rows from SQL Server table(从 SQL Server 表中随机选择 n 行)
                SQL query to select dates between two dates(用于选择两个日期之间的日期的 SQL 查询)
                How can I delete using INNER JOIN with SQL Server?(如何在 SQL Server 中使用 INNER JOIN 进行删除?)
                Table Naming Dilemma: Singular vs. Plural Names(表命名困境:单数与复数名称)
                INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server(INSERT 语句与 FOREIGN KEY 约束冲突 - SQL Server)
                How ROWNUM works in pagination query?(ROWNUM 如何在分页查询中工作?)
                  <bdo id='X4Irz'></bdo><ul id='X4Irz'></ul>
                    <tbody id='X4Irz'></tbody>

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

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

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