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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(Easy One) Using distinct 2

Status
Not open for further replies.

Gatorajc

MIS
Mar 1, 2002
423
US
I need a query that only selects certain projects from a table yet gets all the hours worked on it.

Project Hours
Help Desk 7
Help Desk 9
External 2
Reimage 1
Help Desk 1


I want to get only the Help Desk Project once yet get all the hours. I know there is something with distinct but have not been able to get it to work.
AJ
I would lose my head if it wasn't attached. [roll1]
 
You can do this with a "group by" clause. Something like

select project, sum(hours) as total_hours from your_table
where project = 'Help Desk'
group by project
 
>> "only the Help Desk Project once yet get all the hours"

all the hours individually?

Code:
select Project, Hours
  from yourtable
 where Project="Help Desk"

all the hours summed up?

Code:
select Project, sum(Hours)
  from yourtable
 where Project="Help Desk"
group by Project


rudy
 
Thanks that worked AJ
I would lose my head if it wasn't attached. [roll1]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top