Identify a table with maximum rows in Oracle

后端 未结 7 1459
猫巷女王i
猫巷女王i 2021-01-13 08:15

I have a set of tables in Oracle and I would like to identify the table that contains the maximum number of rows.

So if, A has 200 rows, B has 345 rows and C has 120

7条回答
  •  粉色の甜心
    2021-01-13 08:29

    You could get the same result with one trawl of the data like so:

    SELECT     DISTINCT
               FIRST_VALUE ( t.owner )
                 OVER ( ORDER BY t.num_rows DESC NULLS LAST )
                                                     owner,
               FIRST_VALUE ( t.table_name )
                 OVER ( ORDER BY t.num_rows DESC NULLS LAST )
                                                     table_name,
               FIRST_VALUE ( t.num_rows )
                 OVER ( ORDER BY t.num_rows DESC NULLS LAST )
                                                     num_rows
    FROM       all_tables                            t
    

提交回复
热议问题