Re: Help with SQL statement
Well, when you say that fewer than 2 is good too (meanin 1 or 0), this is the easiest and most straightforward:
select user_id
, max(connecttime)
from logins
group by user_id
This will give you the largest connecttime per user_id when for each user that has at least one login. When you need it for all users even if they never had a login this gives the equivalent result:
select u.user_id
, max(l.connecttime)
from users u
left join logins l
on u.user_id = l.user_id
group by u.user_id
so, max(connecttime) will be NULL for those users without logins.
Subject
Written By
Posted
Re: Help with SQL statement
August 12, 2005 05:47AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.