我有两个数据表,一个代表员工数据,另一个代表员工工作时间。不幸的是,我收到了行格式的员工工时数据,我需要在员工数据旁边的列中表示它......这让我很头疼......请参见下文......
员工工时表:
ID--------Paycode----------Hours----workdate
089999 01 普通--------4.00 -----2013-09-16
089999 02 加班 1.5 ---2.00 -----2013-09-16
089999 03 加班2.0 ---0.50 -----2013-09-16
083131 01 普通--------7.60 -----2013-09-16
083131 02 加班 1.5--- 0.43----- 2013-09-16
员工数据表:
ID ------ 姓 -- 名字 --- 工资等级
-------- baserate --- otherrate089999 史密斯 ----- 约翰 -------- XXX TWU EBA 烫发 Gr6 -- 23.8508 ---- 0.0000
我想要一个查询来产生如下结果,我已经尽我所能尝试了一切,但我无法让它工作......我知道我可能需要一些 php 编程来产生 $ 值但有可能做也通过SQL?非常感谢所有帮助...
ID ------ 姓 -- 名 --- 薪级
------- 01 Hrs--- 01 $ ---- 02 Hrs--- - 02 美元 ---03 小时 -03 美元089999 SMITH ----- JOHN -------- XXX TWU EBA Perm Gr6 ---4.00----95.4032 -- 2.00 ----71.5524--0.50--23.8508
某些具有 ID 的员工可能不存在某些数据,并且在某些列中它会在上面用 0.00 表示...
这是我尝试过的:
<?php
$result1=mysql_query("SELECT `ID Number`, Surname, `First Name`, `Base Rate`, `Other Rate`, `Salary Code Description`, workdate, employeehours
FROM payroll.employeedatanew INNER JOIN payroll.employeehours ON employeedatanew.`ID Number` = employeehours.employeeid
GROUP BY Surname ORDER BY Surname Asc
");
$result2=mysql_query(" SELECT `ID Number`, paycode, workdate, employeehours
FROM payroll.employeedatanew INNER JOIN payroll.employeehours ON employeedatanew.`ID Number` = employeehours.employeeid
ORDER BY Surname Asc
");
while($show1=mysql_fetch_array($result1)){
echo("<tr><td>".$show1['ID Number']."</td><td>".$show1['Surname']."</td><td>".$show1['First Name']."</td><td>".substr($show1['Salary Code Description'],11)."</td></tr>");
}
?>
</table>
<table>
<tr>
<td>1.0x Hrs</td>
<td>1.0x $</td>
<!--<td>1.5x Hrs</td>
<td>1.5x $</td>
<td>2.0x Hrs</td>
<td>2.0x $</td>
<td>Crib Hrs</td>
<td>Crib $</td>
<td>Meal Hrs</td>
<td>Meal $</td> -->
</tr>
<?php
$resultset = array();
while ($row = mysql_fetch_assoc($result3)) { $resultset[] = $row; }
while($show2=mysql_fetch_array($result2)){
if ($show2['paycode'] == "01 Ordinary" && $show2['ID Number'] == $resultset['ID Number']) {
echo ("<tr><td>".$show2['employeehours']."</td>");
$normhourspay = ($show2['employeehours'] * $show3['Base Rate']);
echo ("<td>".$normhourspay."</td></tr>");
} //else {echo("<tr><td>0</td><td>0</td></tr>");}}
和这个:
<table>
<tr class="tabletitles">
<td>Employee ID</td>
<td>Surname</td>
<td>First Name</td>
<td>Pay Grade</td>
<td>1.0x Hrs</td>
<td>1.0x $</td>
<!--<td>1.5x Hrs</td>
<td>1.5x $</td>
<td>2.0x Hrs</td>
<td>2.0x $</td>
<td>Crib Hrs</td>
<td>Crib $</td>
<td>Meal Hrs</td>
<td>Meal $</td> -->
</tr>
<?php
$result1=mysql_query("SELECT `ID Number`, Surname, `First Name`, `Base Rate`, `Other Rate`, `Salary Code Description`, workdate, employeehours
FROM payroll.employeedatanew INNER JOIN payroll.employeehours ON employeedatanew.`ID Number` = employeehours.employeeid
GROUP BY Surname ORDER BY Surname Asc
");
$result2=mysql_query(" SELECT `ID Number`, paycode, workdate, employeehours
FROM payroll.employeedatanew INNER JOIN payroll.employeehours ON employeedatanew.`ID Number` = employeehours.employeeid
ORDER BY Surname Asc
");
while($show1=mysql_fetch_array($result1)){
echo("<tr><td>".$show1['ID Number']."</td><td>".$show1['Surname']."</td><td>".$show1['First Name']."</td><td>".substr($show1['Salary Code Description'],11)."</td></tr>");
}
echo ("</table>");
while($show2=mysql_fetch_array($result2)){
if ($show2['paycode'] == "01 Ordinary" && $show2['ID Number'] == $show1['ID Number']) {
echo ("<td>".$show1['employeehours']."</td>");
$normhourspay = ($show1['employeehours'] * $show1['Base Rate']);
echo ("<td>".$normhourspay."</td></tr>");
} else {echo("<td>0</td><td>0</td>");}
}
请帮忙!