统计报表SQL语句整合

1 篇文章 0 订阅
<?php
class ModelChartChart extends Model {



    public function getMonth($year,$month){
        $sqlY="select month(regdate) as `mon`,count(*) as num from company where year ( regdate) = $year group by month ( regdate)";
        $queryY=$this->db->query($sqlY);
        $dataY= $queryY->rows;
        $sqlM="select day(regdate) as `day`,count(*) as num from company where year ( regdate) = $year and month ( regdate) = $month group by day ( regdate)";
        $queryM=$this->db->query($sqlM);
        $dataM= $queryM->rows;
        $newData['date_m']=$dataY;
        $newData['date_d']=$dataM;
        return $newData;
    }
    public function getActivity($year,$month){
        $sqlY="select month(last_login) as `mon`,count(*) as num from user where year ( last_login) = $year group by month ( last_login)";
        $queryY=$this->db->query($sqlY);
        $dataY= $queryY->rows;
        $sqlM="select day(last_login) as `day`,count(*) as num from user where year ( last_login) = $year and month ( last_login) = $month group by day ( last_login)";
        $queryM=$this->db->query($sqlM);
        $dataM= $queryM->rows;
        $newData['date_m']=$dataY;
        $newData['date_d']=$dataM;
        return $newData;
    }
    public function getTurnover($year,$month){
        $sqlY="select month(a.addeddate) as `mon`,sum((ceil((a.min_salary+a.max_salary)/2))*a.total_person) as num from(select p.id as p_id,p.addeddate,pj.* from project p left join projectjob pj on p.id=pj.projectid where pj.a_status='completed' and  year ( p.addeddate) = $year)a group by month ( a.addeddate)";
        $queryY=$this->db->query($sqlY);
        $dataY= $queryY->rows;
        $sqlM="select day(a.addeddate) as `day`,sum((ceil((a.min_salary+a.max_salary)/2))*a.total_person) as num from(select p.id as p_id,p.addeddate,pj.* from project p left join projectjob pj on p.id=pj.projectid where pj.a_status='completed' and  year ( p.addeddate) = $year and month ( p.addeddate) = $month)a group by day( a.addeddate)";
        $queryM=$this->db->query($sqlM);
        $dataM= $queryM->rows;
        $newData['date_m']=$dataY;
        $newData['date_d']=$dataM;
        return $newData;
        /*
        //$sql="select month(regdate) as `mon`,count(*) as num from company where year ( regdate) = $year group by month ( regdate)";
        $sql="select month(p.addeddate) as `mon`,sum(ceil((pj.min_salary+pj.max_salary)/2)) as num from project p left join projectjob pj on p.id=pj.projectid where pj.a_status='completed' and  year ( p.addeddate) = $year group by month ( p.addeddate)";
        $query=$this->db->query($sql);
        return $query->rows;
        */
    }
    public function getMaster($year,$month){
        $sqlY="select month(datanow) as `mon`,count(*) as num from user where year ( datanow) = $year group by month ( datanow)";
        $queryY=$this->db->query($sqlY);
        $dataY= $queryY->rows;
        $sqlM="select day(datanow) as `day`,count(*) as num from user where year ( datanow) = $year and month ( datanow) = $month group by day ( datanow)";
        $queryM=$this->db->query($sqlM);
        $dataM= $queryM->rows;
        $newData['date_m']=$dataY;
        $newData['date_d']=$dataM;
        return $newData;
        /*
        $sql="select month(datanow) as `mon`,count(*) as num from user where year (datanow) = $year group by month (datanow)";
        $query=$this->db->query($sql);
        return $query->rows;
        */
    }
    public function getProject($year,$month){
        $sqlSM="select month(p.addeddate) as `mon`,count(*) as num from project p left join projectjob pj on p.id=pj.projectid where year(p.addeddate) = $year and (pj.a_status='completed' or pj.a_status='progress' or pj.a_status='employed' ) group by month (p.addeddate)";
        $querySM=$this->db->query($sqlSM);
        $dataSM= $querySM->rows;
        $sqlSD="select day(p.addeddate) as `day`,count(*) as num from project p left join projectjob pj on p.id=pj.projectid where year(p.addeddate) = $year and month ( p.addeddate) = $month and (pj.a_status='completed' or pj.a_status='progress' or pj.a_status='employed' ) group by month (p.addeddate)";
        $querySD=$this->db->query($sqlSD);
        $dataSD= $querySD->rows;

        $sqlTM="select month(p.addeddate) as `mon`,count(*) as num from project p left join projectjob pj on p.id=pj.projectid where year(p.addeddate) = $year  group by month (p.addeddate)";
        $queryTM=$this->db->query($sqlTM);
        $dataTM= $queryTM->rows;
        $sqlTD="select day(p.addeddate) as `day`,count(*) as num from project p left join projectjob pj on p.id=pj.projectid where year(p.addeddate) = $year and month ( p.addeddate) = $month   group by month (p.addeddate)";
        $queryTD=$this->db->query($sqlTD);
        $dataTD= $queryTD->rows;

        $data['date_sm']=$dataSM;
        $data['date_sd']=$dataSD;
        $data['date_tm']=$dataTM;
        $data['date_td']=$dataTD;
        return $data;

    }
    public function getProjectSucceed($year=null){
        if($year==null){
            $year=date('Y',time());//获取当前年份
        }
        $sql="select month(p.addeddate) as `mon`,count(*) as num from project p left join projectjob pj on p.id=pj.projectid where year(p.addeddate) = $year and (pj.a_status='completed' or pj.a_status='progress' or pj.a_status='employed' ) group by month (p.addeddate)";
        $query=$this->db->query($sql);
        return $query->rows;
    }
    public function getProjectTotal($year=null){
        if($year==null){
            $year=date('Y',time());//获取当前年份
        }
        $sql="select month(p.addeddate) as `mon`,count(*) as num from project p left join projectjob pj on p.id=pj.projectid where year(p.addeddate) = $year  group by month (p.addeddate)";
        $query=$this->db->query($sql);
        return $query->rows;
    }


}
?>

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值