0

2 つのデータ テーブルがあります。1 つは従業員データを表し、もう 1 つは従業員の勤務時間を表します。残念ながら、従業員の時間データを行形式で受け取り、それを従業員データの隣の列に表示する必要があります...頭を悩ませています...以下を参照してください...

従業員時間テーブル:

ID--------ペイコード-----営業時間----勤務日

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 ------ 姓 -- 名 --- 給与等級
-------------------基本率 --- その他の率

089999 スミス ----- ジョン -------- XXX TWU EBA パーマ Gr6 -- 23.8508 ---- 0.0000


以下のような結果を生成するクエリが必要で、自分の能力ですべてを試しましたが、動作させることができません... $ 値を生成するためにいくつかの PHP プログラミングが必要な場合があることはわかっていますが、それは可能ですか?それもSQLを介して?すべてのヘルプは大歓迎です...

ID ------ 姓 -- 名 --- 給与等級
------------------- 01 時間 --- 01 $ ---- 02 時間 --- - 02 $ ---03 時間 -03 $

089999 スミス ----- ジョン -------- XXX TWU EBA パーマ 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>");}
                }   

助けてください!

4

1 に答える 1

0
SELECT `ID Number`, Surname, `First Name`, `Salary Code Description`,
                                `Base Rate`, `Other Rate`,
                                MAX((case when employeehours.paycode = '01 Ordinary' then (employeehours.employeehours) end)) AS `1.0 Hours`,
                                MAX((case when employeehours.paycode = '02 Overtime 1.5' then (employeehours.employeehours) end)) AS `1.5 Hours`,
                                MAX((case when employeehours.paycode = '03 Overtime 2.0' then (employeehours.employeehours) end)) AS `2.0 Hours`,
                                MAX((case when employeehours.paycode = '78 Crib' then (employeehours.employeehours) end)) AS `Crib`,
                                MAX((case when employeehours.paycode = 'CZ Meal Allowance PS' then (employeehours.employeehours) end)) AS `Meal Allowance`,
                                MAX((case when employeehours.paycode = '86Y Sick with Cert' then (employeehours.employeehours) end)) AS `Sick with Cert`,
                                MAX((case when employeehours.paycode = '86N Sick without Cert' then (employeehours.employeehours) end)) AS `Sick without Cert`,
                                MAX((case when employeehours.paycode = '87 Sick without Pay' then (employeehours.employeehours) end)) AS `Sick without Pay`,
                                MAX((case when employeehours.paycode = '83 Annual Leave' then (employeehours.employeehours) end)) AS `Annual Leave`,
                                MAX((case when employeehours.paycode = '95 RDO Taken' then (employeehours.employeehours) end)) AS `RDO Taken`,
                                MAX((case when employeehours.paycode = '85 LSL' then (employeehours.employeehours) end)) AS `LSL`,
                                MAX((case when employeehours.paycode = '61 Shift 17.5' then (employeehours.employeehours) end)) AS `Shift 17.5`
                                FROM payroll.employeedatanew INNER JOIN payroll.employeehours ON employeedatanew.`ID Number` = employeehours.employeeid
                                Group By Surname
                                ORDER BY Surname asc, `1.0 Hours` desc, `1.5 Hours` desc, `2.0 Hours` desc

これはトリックでした、見てくれたみんなに感謝します:)

于 2013-10-11T04:27:17.333 に答える