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.
| 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 ejoin efmextract.dbo.tbl_caseparticipation cp on cp.col_appid = e.col_appidleft outer join efmextract.dbo.tbl_caseclosure ccon e.col_appid=cc.col_idnumleft outer join OSPR_WorkArea.dbo.onet2010 ocon e.col_onetcode=oc.soc_rawwhere 1=1and cp.col_participationdate <= @Enddateand (cc.col_closuredate >= @bgnDateor cc.col_closuredate is null) and E.col_programtypeid=2and cp.col_programid = 2 and e.col_enrollmentparentid = 0and e.col_actbegindate is not nulland e.col_sda-1=@rgngroup by oc.sochighorder by oc.sochighRoger DeFour |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-21 : 12:26:48
|
| define top 5is it top 5 programs from whole tableor is it top 5 based on a subgroup of data?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2012-09-21 : 12:29:57
|
| top 5 occupations from a subgroup of dataRoger DeFour |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-21 : 13:05:06
|
| show sample data and output required------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Trininole
Yak Posting Veteran
83 Posts |
Posted - 2012-09-21 : 14:05:48
|
| Occupations amount in regionAccountants 5Administrative Services Managers 3Adult Literacy, and teachers 1Ambulance Drivers and Attendants 1Amusement and Recreation Attendants 9Roger DeFour |
 |
|
|
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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|