Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help With SQL Query
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 09/26/2012 :  12:58:49  Show Profile  Reply with Quote
Hi. I have a staff table and an assignments table. A staff member can have many assignments. I want to query the staff members based on their number of assignments for the month. The staff members should be ordered by the number of assignments from least to greatest. Here's what I'm starting with:

SELECT staff.staff_id, staff.first_name + ' ' + staff.last_name, COUNT( ...) this is where I'm not sure what to do? WHERE staff.staff_id = assignments.staff_id ORDER BY COUNT( ...again not sure...)

Thanks for any help you can provide. :-)

Constraint Violating Yak Guru

277 Posts

Posted - 09/26/2012 :  13:16:23  Show Profile  Reply with Quote
PLease show some sample of data to show us what your needs are.

the structure of the table will help too.

Joins are what RDBMS's do for a living
Go to Top of Page

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 09/26/2012 :  13:20:11  Show Profile  Reply with Quote
Something like this?
	s.first_name + ' ' + s.last_name AS staff_name,
	COUNT(DISTINCT a.assignment_id) AS Assignments
	staff s
	LEFT JOIN assignments a ON
		a.staff_id = s.staff_id
	s.first_name + ' ' + s.last_name
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000