2016-12-20 29 views
0

を使用して給与の平均値を計算するためにどのように、私は会社名、名称、分給与、最大給与、最小の経験、最高の経験などをジョブポストテーブルを持っている詳述すると最低賃金と最大給与列

私は平均給与と経験を出そうとしています。 平均的なsalと平均的なexpericeを提供する役割データベース開発者で会社名(xxx)をリストしたいと思いました。


 
declare user_details cursor FOR 
 
\t \t \t select up.role,ur.years,ur.month,upd.current_ctc from user_registration ur 
 
\t \t \t left join user_personal_details upd on upd.registration_user_id=ur.iduser_registration 
 
\t \t \t left join user_projects up on up.employee_id=ur.iduser_registration 
 
\t \t \t where ur.iduser_registration=p_userID; 
 
\t \t open user_details; 
 
\t \t fetch user_details into v_role,v_exp_years,v_exp_months,v_current_ctc; 
 
\t \t #select v_role,v_exp_years,v_exp_months,v_current_ctc; 
 
\t \t set v_experience= concat(COALESCE(v_exp_years,0),'.',COALESCE(v_exp_months,0)); 
 
\t \t #select v_experience; 
 
\t \t \t BLOCK2: BEGIN 
 
\t \t \t \t declare jobs_list cursor for 
 
\t \t \t \t \t select jobid,cr.company_name,jp.max_salary from job_posts jp 
 
\t \t \t \t \t join client_registration cr on cr.idclient_registration=jp.idclient_registration 
 
\t \t \t \t \t where jp.designation=v_role 
 
\t \t \t \t \t and v_experience between jp.min_experience and jp.max_experience 
 
\t \t \t \t \t group by jp.jobid order by jp.createdon limit 5; 
 

 
\t \t \t \t DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finished = 1; 
 
\t \t \t \t \t OPEN jobs_list; 
 
\t \t \t \t \t set v_result_joblist=''; 
 
\t \t \t \t \t set v_result_role_list=''; 
 
\t \t \t \t \t jobs_list_loop: LOOP 
 
\t \t \t \t \t FETCH FROM jobs_list INTO v_jobID,v_company_name,v_max_salary; 
 

 
\t \t \t \t \t \t IF v_finished=1 THEN LEAVE jobs_list_loop;  END IF; 
 
\t \t \t \t \t \t set v_result_joblist=concat(v_result_joblist,v_jobID,'-',v_company_name,'-',v_max_salary,','); 
 
\t 
 
\t \t \t \t \t \t \t if(v_result_role_list is null or v_result_role_list='') then 
 
\t \t \t \t \t \t \t \t set v_result_role_list= v_company_name; 
 
\t \t \t \t \t \t \t else       
 
\t \t \t \t \t \t \t \t set v_result_role_list=concat_ws('-',v_result_role_list,v_company_name); 
 
\t \t \t \t \t \t \t end if; 
 
\t \t \t \t \t \t \t \t BLOCK3: BEGIN 
 
\t \t \t \t \t \t \t \t \t declare role_wise_jobposts cursor for 
 
\t \t \t \t \t \t \t \t \t \t select jp.designation,max(jp.max_salary),min(jp.min_salary),max(jp.max_experience),min(jp.min_experience) from job_posts jp 
 
\t \t \t \t \t \t \t \t \t \t join client_registration cr on cr.idclient_registration=jp.idclient_registration 
 
\t \t \t \t \t \t \t \t \t \t where cr.company_name=v_company_name 
 
\t \t \t \t \t \t \t \t \t \t group by jp.designation order by jp.createdon; 
 

 
\t \t \t \t \t \t \t \t \t \t DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finish = 1; 
 

 
\t \t \t \t \t \t \t \t \t \t OPEN role_wise_jobposts; 
 
\t \t \t \t \t \t \t \t \t \t \t role_wise_joblist: loop 
 
\t \t \t \t \t \t \t \t \t \t \t FETCH FROM role_wise_jobposts INTO v_role_list,v_max_salary,v_min_salary,v_max_exp,v_min_exp; 
 
\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t \t \t \t IF v_finish=1 THEN    LEAVE role_wise_joblist;    END IF; 
 
\t \t \t \t \t \t \t \t \t \t \t set v_result_role_list=concat_ws(',',v_result_role_list,concat('_',v_role_list),v_max_salary,v_min_salary,v_max_exp,v_min_exp); 
 
\t \t \t \t \t \t \t \t \t \t END LOOP role_wise_joblist; 
 
\t \t \t \t \t \t \t \t \t \t \t set v_finish=0; 
 
\t \t \t \t \t \t \t \t \t \t \t set v_result_role_list=concat_ws('-',v_result_role_list); 
 
\t \t \t \t \t \t \t \t \t \t CLOSE role_wise_jobposts; 
 
\t \t \t \t \t \t \t \t \t \t \t #select v_result_role_list; 
 
\t \t \t \t \t \t \t \t END BLOCK3; 
 

 
\t \t \t \t \t \t \t #select v_result_role_list; 
 
\t \t \t \t END LOOP jobs_list_loop; 
 

 
\t \t \t END BLOCK2; 
 
\t close user_details; 
 
\t select v_result_joblist UNION select v_result_role_list; 
 
END

+0

が私たちにいくつかのテーブルデータを共有してください。それは、最大値と最小値を格納するために私を奇妙に思います。 –

答えて

0

このようなクエリ行います

SELECT avg(col1 + col2) 
FROM test 
WHERE uid=5; 

SQL Fiddle Demo

+0

jobidでjob_postsグループからavg(min_salary + max_salary)、min_salary、max_salaryを選択してください –

+0

こんにちは、私は正しい結果を返すわけではありません。 –

関連する問題