Most Occurring Value

From: Mike Ginsburg <mginsburg(at)collaborativefusion(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Most Occurring Value
Date: 2008-04-08 00:42:18
Message-ID: 47FABF6A.8000702@collaborativefusion.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

There is probably a really simple solution for this problem, but for the
life of me I can't see to think of it. I have three tables

--contains u/p for all users in the site
TABLE users (user_id INT primary key, username VARCHAR(50), password TEXT)
--list of all possible events (login, logout, timeout)
TABLE events (event_id INT primary key, event VARCHAR(255))
--logs the activity of all users logging in/out, etc
TABLE log (log_id INT primary key, user_id INT REFERENCES users,
event_id INT REFERENCES event);

How would I query to find out which user has the most activity?
SELECT user_id, COUNT(event_id)
FROM log
GROUP BY (user_id)
HAVNG COUNT(event_id) = ???

Any and all help is appreciated. Thank you.

Mike Ginsburg
mginsburg(at)collaborativefusion(dot)com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Wilson 2008-04-08 00:54:38 Re: select distinct and index usage
Previous Message Gregory Stark 2008-04-07 23:57:21 Re: select distinct and index usage