开发者

help with query [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have table having staffid and studentid in which staffid repeating number开发者_开发知识库 of times.

staffid | studentid
___________________
5       |     4
1       |     6
5       |     3
5       |     4
1       |     1

IN this way I want to select those staffid with their count in order.

staffid 5 (3)
staffid 1 (2)


If you want the counts in descending order, then there has to be an 'order by' clause in the query.

select staffid, count (*) 
from table_name 
group by staffid 
order by count (*) desc


SELECT COUNT(staffid) FROM table_name group by staffid 


Assuming you want to actually know which staffid each count is for, you need to include that column in the select list.

SELECT staffid, COUNT(*) 
FROM tablename 
GROUP BY staffid


select count(studentid) from table group by staffid


Assuming you are using an SQL database, try something like:

SELECT staffid, count(studentid) 
FROM tablename 
GROUP BY staffid  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜