Interview Question
Software Engineer / DevelopersCountry: United States
SELECT user FROM Table GROUP BY user HAVING COUNT(user) = (SELECT COUNT(user) FROM Table GROUP BY user ORDER BY COUNT(user) DESC LIMIT 1)
Good answer, but this doesn't work in Oracle.
Need to use "where ROWNUM=1" in Oracle instead of "limit 1".
I think this will work:
SELECT user FROM Table GROUP BY user HAVING COUNT(user) =
(SELECT max(c) FROM (SELECT COUNT(user) c FROM Table GROUP BY user))
#include<iostream>
using namespace std;
int sort(int arr[],int l);
int main()
{
int arr[10] = {3,6,2,1,0,5,7,8,3,4};
int arr2[10]= {4,1,6,3,8,10,11,5,9,2};
sort(arr,10);
sort(arr2,10);
int j=0;
for(int i=0;i<10;i++)
{
while(arr[i]>arr2[j])
{
cout<<"("<<arr[i]<<","<<arr2[j]<<")";
j++;
}
}
}
int sort(int arr[],int l)
{
int min;
int k=0;
for(int i=0;i<l;i++)
{
min =arr[i];
for(int j=i;j<l;j++)
{
if(min > arr[j])
{
min = arr[j];
k=j;
}
}
arr[k] =arr[i];
arr[i] = min;
}
}
If this is a SQL question, it's pretty straight forward. The below returns a sorted list with the most logins at the top. If you need only to return a single row, simply turn this into a sub-query and select user_id from sub-query where rownum = 1.
select
user_id
,count(date) as logins
from table_name
group by
user_id
order by count(date) desc
select userid, count(userid) as num
- Anonymous October 14, 2014from table
group by userid
order by num desc limit 1