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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 top 5 jobtitles enrolled

Author  Topic 

Trininole
Yak Posting Veteran

83 Posts

Posted - 2012-09-21 : 12:25:47
Hello there, I am trying to seek the top 5 occupations for the wia program in region 1. Here is my query and I would appreciate if someone can tell if i am doing this correctly:

Select top 5 oc.socHigh occupations , count(distinct e.col_appid) [WIA Adults with occupations]
from efmextract.dbo.tbl_enrollment e
join efmextract.dbo.tbl_caseparticipation cp
on cp.col_appid = e.col_appid
left outer join efmextract.dbo.tbl_caseclosure cc
on e.col_appid=cc.col_idnum
left outer join OSPR_WorkArea.dbo.onet2010 oc
on e.col_onetcode=oc.soc_raw
where 1=1
and cp.col_participationdate <= @Enddate
and (cc.col_closuredate >= @bgnDate
or cc.col_closuredate is null)
and E.col_programtypeid=2
and cp.col_programid = 2
and e.col_enrollmentparentid = 0
and e.col_actbegindate is not null
and e.col_sda-1=@rgn
group by oc.sochigh
order by oc.sochigh

Roger DeFour

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-21 : 12:26:48
define top 5
is it top 5 programs from whole table
or is it top 5 based on a subgroup of data?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Trininole
Yak Posting Veteran

83 Posts

Posted - 2012-09-21 : 12:29:57
top 5 occupations from a subgroup of data

Roger DeFour
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-21 : 13:05:06
show sample data and output required

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Trininole
Yak Posting Veteran

83 Posts

Posted - 2012-09-21 : 14:05:48
Occupations amount in region

Accountants 5
Administrative Services Managers 3
Adult Literacy, and teachers 1
Ambulance Drivers and Attendants 1
Amusement and Recreation Attendants 9

Roger DeFour
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-21 : 14:12:34
if you want only 5 rows, then just change

order by [WIA Adults with occupations]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -