获取ORACLE中每个号码的最新记录

时间:2016-10-20 03:49:18

标签: sql oracle oracle-sqldeveloper

我在Trans表中有一组数据。其中包含transno的多个交易。我需要获取每个transno的最新交易记录。 这些数据存储在Oracle数据库中。

enter image description here

我尝试过以下查询,每次都进行少量更改。但我只给了一个原始的。该表包含超过1m的记录。

select * from (select transid,transno,transdate,transtype from trans order by TRANSID desc) where rownum <= 1

请帮忙。

3 个答案:

答案 0 :(得分:3)

您需要使用R version 3.3.1 (2016-06-21) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] glmnet_2.0-2 foreach_1.4.3 Matrix_1.2-7.1 devtools_1.12.0 loaded via a namespace (and not attached): [1] httr_1.2.1 R6_2.2.0 tools_3.3.1 withr_1.0.2 curl_2.1 [6] memoise_1.0.0 codetools_0.2-15 grid_3.3.1 iterators_1.0.8 digest_0.6.10 [11] lattice_0.20-34 窗口功能获取所有ROW_NUMBER的最新transdate

transno

答案 1 :(得分:0)

让我知道这是否有效。

SELECT * FROM trans GROUP BY transno ORDER BY transid DESC LIMIT 1

我不是MySQL大师,所以请告诉我。

答案 2 :(得分:0)

此解决方案的最佳方式是@ Prdp的方式。但还有另一种方式。您可以像这样使用select * from trans t inner join ( select transno, max(transdatetime) maxtransdatetime from trans group by transno ) s on s.transno = t.transno and s.maxtransdatetime = t.transdatetime

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/image_one"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/image_two"/>

    <ImageView
        android:id="@+id/image_two"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/image_two"/>

</LinearLayout>