1

我在查询中找不到错误:

SELECT
u.Table_Name, 
count(distinct c.Column_Name), 
sum(u.num_rows)    
FROM User_Tab_Columns c, User_Tables u    
WHERE   u.TABLE_NAME = c.TABLE_NAME    
group by u.Table_Name;

结果是:

TABLE_NAME                     COUNT(DISTINCTC.COLUMN_NAME) SUM(U.NUM_ROWS)    
------------------------------ ---------------------------- ---------------
DEPT                                                      3              12     
EMP                                                       8             112

它应该是:

 TABLE_NAME                     COUNT(DISTINCTC.COLUMN_NAME) SUM(U.NUM_ROWS)    
    ------------------------------ ---------------------------- ---------------
    DEPT                                                      3              4     
    EMP                                                       8             14

所以查询多个行数和列数但我不知道为什么?

4

1 回答 1

2

由于每个表的行数,您可以简单地按它进行分组:

SELECT
u.Table_Name, 
count(*), 
u.num_rows    
FROM User_Tab_Columns c, User_Tables u    
WHERE   u.TABLE_NAME = c.TABLE_NAME    
group by u.Table_Name, u.num_rows;
于 2012-12-16T17:24:40.300 回答