Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

complex query

Status
Not open for further replies.

twcman

Programmer
Jun 28, 2001
284
0
0
US
I need to build a query. I have a table with user login log info. every time a user logs in, an entry with sessionstart(activity_id) and user_name is entered in the table. I need a query that counts the number of times each user has logged in. This is the sql that I have so far:

select count(*)activity_id from event_log where activity_id=3 and user_name=(select distinct(user_name) from event_log)

Chris

Chris Scott
The Whole Computer Medical Systems
 
Hi Chris,

SELECT COUNT(activity_id), user_name from event_log
where activity_id = 3
group by user_name

HTH,

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'm not as think as you confused I am.
-----------
Flabbergasted (a.): Amazed at how much weight one has gained.
-----------
Oyster (n.): One who sprinkles their conversation with Yiddish expressions.
 
slight mod.

SELECT COUNT(activity_id)
should be
Code:
SELECT COUNT(activity_id) [COLOR=red]as someNameYouWantToUse[/color]

Beware of programmers who carry screwdrivers.
 
Zactamundo, else it'd be called COMPUTED_COLUMN_1 or some such nonsense.

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'm not as think as you confused I am.
-----------
Flabbergasted (a.): Amazed at how much weight one has gained.
-----------
Oyster (n.): One who sprinkles their conversation with Yiddish expressions.
 
I have a table with names and addresses of people. There are many people from the same city. I need to take only one from NYC, only one from Chicago, only one from LA etc. I don’t care who are the ones who would not be selected. DISTINCT would not resolve my problem. Currently I am doing it programmatically with a short SP using cursor. I am confident that there is a better way to accomplish it. Can someone help me with this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top