简体   繁体   中英

SQL for specific count of table entries

I am trying to create an SQL query to return some specific information.

214 6255    en-us   4  
62  6259    en-us   4  
64  6260    en-us   4  
63  6262    en-us   4  
69  6264    en-us   4  
70  6255    en-us   4  

This would be an example layout in the table. The first column would be a for example spID, the second is userID.

What I need to find is the count of the rows that the UserID has. So in the above example the UserID 6255 has 2. I would like the results to be like this:

6255   2  
6259   1  
6262   1  
6264   1

How could I do this?

wait? all your doing is counting amount of times the user turns up in your table?

if so cant you just...

Select userid, COUNT(userid) as UserTotal
From yourtable
group by userid

or do you need more?

select userID,  count(*) as TotalEntries
from table_name
group by userID

Hope this solves your query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM