0

尝试对这些行进行计数 COUNT(engineerName) ASengineerCount, Count(managerName) as managerCount, Count(isContractor) ascontractorCount 但它始终返回所有三个相同的数字。所以我试图为每个添加一个 Where,Example Count(isContractor where isContractor = 'yes') ascontractorCount 但遇到错误请帮忙,谢谢。

<?php


        clASs EfficiencyController extends DooController
        {


        function getEfficiency(){

        include './protected/config/db.conf.php';
        Doo::db()->setDb($dbconfig, 'local_network');


        $Vendor = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['Vendor'] : $_GET['Vendor'];
        $date   =   ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['date'] : $_GET['date'];
        $level   =  ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['level'] : $_GET['level'];
            switch($level) {
            case "Region":
            case "area":
                $Market99="";
                break;
            default:
                $Market99=$level;
                break;

        }
    {
        //
        // LUCENT,NORTEL
        //


        $query = " SELECT 
                  DayKey,
                Market99,
                Region,
                areaName,
                Sum(Total_Sites) as totalCount,
                Max(engineerCount) AS engineerCount,
                Max(managerCount) AS managerCount,
                Max(contractorCount) AS contractorCount,
                SC_Type,
                Sum(Total_Carriers),
                Sum(Total_Sectors),
                Vendor 
                FROM
                network.envEquipSummaryConfig a
            Left Join
            (SELECT 
                market,
                    areaName,
                    COUNT(engineerName) AS engineerCount,
                    Count(managerName) as managerCount,
                    Count(isContractor) as contractorCount
            FROM
                employee.employees
            GROUP BY market
            ORDER BY COUNT(market) DESC) b ON a.Market99 = b.market
            Where
            a.DayKey <= \"$date\" and a.Vendor = \"$Vendor\" 
            Group By Market99 asc";


            switch($level) {
                case "region":
                        $query = $query. " order by region ASC";
                        break;
                        case "area":
                        $query = $query. " order by areaName ASC";
                        break;
                default;
                        $query = $query. " order by Market99 ASC";
                        break;  

            }

        }
        //echo $query; exit;    

        $this->setContentType('xml');
        $result = Doo::db()->fetchAll($query);





        printf("<root>\n");
        if(count($result) > 0)
        foreach($result AS $row) {


                    printf("\t<data>\n");
                printf("\t\t<date>%s</date>\n",$row["DayKey"]);
                printf("\t\t<vName>%s</vName>\n",$row["Vendor"]);
                printf("\t\t<location>%s</location>\n",$row["Market99"]);
                printf("\t\t<toCount>%s</toCount>\n",$row["totalCount"]);
                printf("\t\t<enCount>%s</enCount>\n",$row["engineerCount"]);
                printf("\t\t<mnCount>%s</mnCount>\n",$row["managerCount"]);
                printf("\t\t<cnCount>%s</cnCount>\n",$row["contractorCount"]);


                printf("\t</data>\n");

        }
      printf("</root>\n");

    }
}   

?>
4

1 回答 1

0
SELECT 
  market,
  areaName,
  COUNT(engineerName) AS engineerCount,
  Count(managerName) as managerCount,
  Count(isContractor) as contractorCount
FROM
  employee.employees
GROUP BY market

应该

Group By market,areaName猜测。

这就是它所能看到的一切,因为您几乎没有提供任何有用的信息。

于 2012-06-09T17:12:32.230 回答