help with query [closed]
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
精彩评论