执行时比较两个查询

时间:2015-10-16 10:52:28

标签: mysql

$query=mysql_query("SELECTcom_jobcard.job_card_num,process.process_name,employee.emp_name,employee.emp_code ,SUM(worked_qty) FROMcom_jobcard
INNER JOIN timer_completed ON timer_completed.job_card_id = com_jobcard.id 
INNER JOIN process ON process.id = timer_completed.process_id 
INNER JOIN employee ON employee.id = timer_completed.employee_id
AND job_card_id = ( SELECT id FROM com_jobcard WHERE job_card_num =  'JCID-1271742')
GROUP BY process.process_name,employee.emp_name ");

$query1 = mysql_query("SELECT com_jobcard.job_card_num,process.process_name,employee.emp_name,employee.emp_code,SUM(qc.rework_qty),qc.report_date,qc.id FROM qc 
INNER JOIN com_jobcard ON qc.job_card_id = com_jobcard.id
INNER JOIN process ON process.id = qc.process_id
INNER JOIN qc_employees ON qc_employees.qc_id = qc.id
INNER JOIN employee ON employee.id = qc_employees.employee_id
AND qc_employees.qc_id = (SELECT qc.id
FROM qc
INNER JOIN com_jobcard ON qc.job_card_id = com_jobcard.id
AND com_jobcard.job_card_num =  'JCID-1271742')
GROUP BY process.process_name,employee.emp_name");
while ($row = mysql_fetch_array($query)) {
$row1 = mysql_fetch_array($query1);
if( ($row[1] == $row1[1]) && ($row[3] == $row1[3] ))
{
echo $row1[0] .$row1[1]  .$row1[2] .$row1[3] .$row1[4];
}
}

亲爱的朋友我正在同时执行2个查询,但我想比较结果集$row[1] == $row1[1]) && ($row[3] == $row1[3]满足条件然后必须返回结果,但好像现在它返回什么都没有任何人建议我如何比较两个查询的结果集,而不是使用IF我也使用了While语句,虽然我没有收到结果。 请帮我! 谢谢!

1 个答案:

答案 0 :(得分:0)

像这样使用

$row1 = mysql_fetch_array($query1);
while ($row = mysql_fetch_array($query)) {
 while($row1) {
   if( ($row['process_name'] == $row1['process_name']) && ($row['emp_name'] == $row1['emp_name'] ))
    {
      echo $row1['job_card_num'] .$row1['process_name']  .$row1['emp_name'] .$row1['emp_code'] .$row1['sum_qty'];
    }
 }
}

因为你使用了没有值的$ row [1] $ row1 [1]。  我ahev在你的查询中使用别名vakue作为SUM(qc.rework_qty)sum_qty