Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with query -- distinct count

Status
Not open for further replies.

mrDrive

MIS
Aug 29, 2002
94
0
0
US
Hi,

I have a table:

uid task_id yr
------------------------
1 101 08
2 101 09
3 102 08
4 102 09
5 102 10

I need to determine 2 things:
1) distinct list of yr's
2) count of task_id's for a particular yr

So, in my simplified example the results would look like:

yr task_id_count
-------------------------
08 2
09 2
10 1

I've tried using a self-join w/ no luck:

select distinct t1.yr as yr,
(select count(distinct task_id)
from mytable
where t1.task_id = t2.task_id) as task_id_count
from mytable t1 inner join
mytable t2
on t1.task_id = t2.task_id
order by t1.yr

Any help would be greatly appreciated!
-mD.
 
Code:
Select yr, Count(task_id) As Task_ID_Count
From   TableNameHere
Group By yr
Order By yr



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top