Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Help with a query

Author  Topic 

Daniel Israel
Starting Member

15 Posts

Posted - 2007-07-30 : 19:47:43

Hello,

I'm trying to figure out this query, but I'm having trouble (not sure it's possible in one query).

I have a table that tracks number of logins like so:

LoginName, IPAddress, Count, Date

Each time someone logs in, it will check if they've logged in on that date with that login and IP. If they have, it increments the count. If not, it will create a new record and set Count to 1.

What I'd like is to have a Query that returns a list of LoginName with a count of unique IPAddress with each LoginName (and, ideally, the total number of logins on that LoginName).

Any help on this would be appreciated.

-D. Israel

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-30 : 21:46:37
try something like

SELECT LoginName, IPAddress, COUNT(*) As NumIP , SUM(Count)
FROM LoginTable
GROUP BY LoginName, IPAddress


Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -