Interview Question in Data Warehousing


 

Interview Question :: Can anyone help me with SQL


I am trying to figure out the simplest way to count the # of times a user ID appears in a column. FYI the user ID is defined as char not numeric

I have a query that tells me what users are accessing tables in our data warehouse directly rather than via the table view which violates our policy for queries run in production and I see the same user ID many times. My problem is that this query returns 700 rows so that is way to many to sift through manually. I need to narrow it down so that I only see each user once and how many times their ID appeared in the column.
Answers to "Can anyone help me with SQL"
RE: Can anyone help me with SQL?

This is MySQL syntax



SELECT user_id, COUNT(user_id) as total FROM table_name GROUP BY user_id



Each row returned will have the unique 'user_id' and 'total' number of times it apears.



--

Alex
 
Vote for this answer ::  
RE: Can anyone help me with SQL?

select UserID, count(*) from [TableName]

group by UserID
 
Vote for this answer ::  
Update Alert Setting