database - SQL Select record of the max aggregate -


i need select "job role desc" of maximum of aggregates have achieved. table looks follows.

[job role description] |  [number of placements] ------------------------------------------------ training bi                     24 system analyst                  23 data analyst                    24 data consultant                 25 db programmer                   24 

the job_role_desc column table joined job_role_id. used following code achieve this.

select      job_role_dim.job_role_desc "job role description" ,     sum(fact_accounts.no_of_placements) "number of placements"       fact_accounts  inner join      job_role_dim on job_role_dim.job_role_id =  fact_accounts.fk3_job_role_id  group      job_role_dim.job_role_desc 

how can modify above code display job_role_desc has maximum number of placements? thank help.

you can use row_number() or dense_rank():

select ja.* (select j.job_role_desc "job role description" ,                 sum(a.no_of_placements) "number of placements",              row_number() on (order sum(a.no_of_placements) desc) seqnum       fact_accounts inner join            job_role_dim j            on j.job_role_id = a.fk3_job_role_id       group j.job_role_desc      ) ja seqnum = 1; 

if want versions maximum, use dense_rank() or rank().


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -