[英]SQL for specific count of table entries
I am trying to create an SQL
query to return some specific information. 我试图创建一个SQL
查询来返回一些特定的信息。
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. 第一列是例如spID,第二列是userID。
What I need to find is the count of the rows that the UserID has. 我需要找到的是UserID具有的行数。 So in the above example the UserID 6255 has 2. I would like the results to be like this: 所以在上面的例子中,UserID 6255有2.我希望结果如下:
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. 希望这能解决您的疑问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.