I can’t find a mistake in my query:
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;
the result is:
TABLE_NAME COUNT(DISTINCTC.COLUMN_NAME) SUM(U.NUM_ROWS)
------------------------------ ---------------------------- ---------------
DEPT 3 12
EMP 8 112
and it should be:
TABLE_NAME COUNT(DISTINCTC.COLUMN_NAME) SUM(U.NUM_ROWS)
------------------------------ ---------------------------- ---------------
DEPT 3 4
EMP 8 14
So the query multiple number of rows and number of columns but I don’t know why?
Since the number of rows is per table, you can simply group by it: