Sorry TOM
Dasarathiratha, November 12, 2012 - 11:11 am UTC
Hi Tom,
sorry that i am unaware that it is ur interview question.I got it from the link that u have provided.
Ans:What ever the query i have written that can find all the users who have the maximum no of objects.
I saw ur queries,these are also good.
But i have modified the query to another format:
SQL> select count(1) no,owner from all_tables
group by owner
having no=(select max(count(1)) from all_tables group by owner)
But sorry TOM,furhter i will review my quesiton and if it seems to be appropriate for then i will ask you
November 14, 2012 - 10:13 am UTC
don't be sorry - I found it amusing, it was a variation on a theme, a query I am very familiar with ;)
never use count(1) - that is silly, it makes you look bad.
why would you count the number of non-null number ones when you wanted to count the number of rows?
count(*) counts rows
count(1) counts the number of non-null number ones
count(1) - we had to file a bug and write an optimization that turns count(1) into count(*) so it count(1) wouldn't run for so long!
count(*) is what you mean to use!!!
Thanks Tom
dasarathi, November 14, 2012 - 2:34 pm UTC
thanks a lot TOM..
KEEP counting
Duke Ganote, November 14, 2012 - 4:05 pm UTC
select MIN(owner) KEEP (dense_rank first order by cnt desc)
AS first_owner_with_the_most
, COUNT(owner) KEEP (dense_rank first order by cnt desc)
AS how_many_owner_with_the_most
, max(cnt)
AS the_most
from (
select count(*) cnt
, owner
from dba_objects
group by owner
);
FIRST_OWNER_WITH_THE_MOST HOW_MANY_OWNER_WITH_THE_MOST THE_MOST
------------------------------ ---------------------------- ----------
SYS 1 9822
Example with duplicates:
select MIN(owner) KEEP (dense_rank first order by cnt desc)
AS first_owner_with_the_most
, COUNT(owner) KEEP (dense_rank first order by cnt desc)
AS how_many_owner_with_the_most
, max(cnt)
AS the_most
from (
select 2 as cnt, cast('Tom' as varchar2(30)) as owner from dual union all
select 2 as cnt, 'R' as owner from dual union all
select 2 as cnt, 'Kyte' as owner from dual union all
select 1 as cnt, 'me' as owner from dual
);
FIRST_OWNER_WITH_THE_MOST HOW_MANY_OWNER_WITH_THE_MOST THE_MOST
------------------------------ ---------------------------- ----------
Kyte 3 2
Interview question
Rajeshwaran, Jeyabal, November 19, 2012 - 7:30 am UTC