如何使用连接查询连接四个表

时间:2016-03-22 10:20:09

标签: php mysql laravel-5

我有4张桌子

回答

id
qid (question id)
appid (applicant id)
answer (user answer 1/0)

问题

id
jobid (job type id)
questiontext 
weight ( it could be 1/0)

postnewjb

id
jobid
jobtxt

申请人

id
jobid
name
email

我必须使用以下公式计算特定jobid的所有用户的答案百分比

例如用户回答了3个问题

每个答案的百分比= 100 /(总无问题)

如果用户对问题的答案为1且问题权重为1,则应添加问题的完整百分比。我们应该计算所有%

的总和
 $jobid=Postnewjob::where('id',$jobid)->get();

 foreach($jobid as $job){
  $jobId=$job->jobid;
 }

 $apps=applicants::where('jobid','=',$jobId)->get();

 foreach($apps as $apo){
  $appid[]=$apo->id;
 }


 $score=answers::whereIn('appid',$appid)->where('jobid','=',$jobId)->get();

 $qid=array();
 foreach($score as $s){
  $qid[]=$s->qid;
 }
 $queid=questions::whereIn('id',$qid)->get();

 $calscore=100/(count($queid));

0 个答案:

没有答案