Php 从周二开始每周分组使用时,Codeigniter在何处出现问题

Php 从周二开始每周分组使用时,Codeigniter在何处出现问题,php,mysql,codeigniter,Php,Mysql,Codeigniter,我必须在CodeIgniter查询中使用yearweek()从星期二开始每周对数据进行分组。这很好,没有问题。然后主要的问题是过滤was不适用于星期二日期。在where on Sunday日期中仅过滤yearweek() 我试着写了一个运行良好的原始查询。然后我分析了我的问题,然后我发现了问题。这并没有在where列和值之间显示相等(=)符号。我将我的CodeIgniter代码和正确的原始查询放在下面,然后是当前的CodeIgniter等效查询 function getbranchSalesre

我必须在CodeIgniter查询中使用yearweek()从星期二开始每周对数据进行分组。这很好,没有问题。然后主要的问题是过滤was不适用于星期二日期。在where on Sunday日期中仅过滤yearweek()

我试着写了一个运行良好的原始查询。然后我分析了我的问题,然后我发现了问题。这并没有在where列和值之间显示相等(=)符号。我将我的CodeIgniter代码和正确的原始查询放在下面,然后是当前的CodeIgniter等效查询

function getbranchSalesreportshift($limit,$offset,$order_column,$order_type,$parameters)
{
     $this->db->select("str_to_date(concat(yearweek(s.creationdate), 'tuesday'), '%X%V %W') as week,b.name as branchname,g.name as groupname,st.name as shiftname,count(*) as total_sales_party,sum(s.price) as total_sales,count(case when salesAdvanceAmount > 0 then s.customerid end) as total_advance_party,sum(case when salesAdvanceAmount > 0 then salesAdvanceAmount end) as total_advance_amount,count(CASE WHEN DATE(s.creationdate) <> Date(customerCreationDate) then 1 end ) as old_sales_party,sum(CASE WHEN DATE(s.creationdate) <> Date(customerCreationDate) THEN s.price END ) as old_sales_amount,count(CASE WHEN DATE(s.creationdate) = Date(customerCreationDate) THEN 1 END ) as new_sales_party,sum(CASE WHEN DATE(s.creationdate) = Date(customerCreationDate) THEN s.price END ) as new_sales_amount,count(returnID) as return_product,sum(orn.price) as return_amount ");
     if($parameters['shift']!=NULL){
       $this->db->like('s.shiftID',$parameters['shift']);
    }
    if($parameters['cdatefrom']!=NULL){
       // $this->db->where('yearweek(s.creationdate)',date('YW',strtotime($parameters['cdatefrom'])));
      $this->db->where('str_to_date(concat(yearweek(s.creationdate), "tuesday"), "%X%V %W")',date('YW',strtotime($parameters['cdatefrom'])));
    }
    $this->db->group_by(array("s.shiftID", "str_to_date(concat(yearweek(s.creationdate), 'tuesday'), '%X%V %W')"));
    if(empty($order_column) || empty($order_type)){
        $this->db->order_by('yearweek(s.creationdate)','asc');
    }else{
        $this->db->order_by($order_column,$order_type);
    } 
    if($limit!=0){
        $this->db->limit($limit,$offset);
    }
     $uid=$this->session->userdata('id'); 
    $this->db->where('b.ownerid',$uid); 
    $this->db->join('open_returns orn','s.branchID=orn.branchID ','left');
    $this->db->join('shifts st','s.shiftID=st.id ','left');
    $this->db->join('group g','s.groupID=g.id ','left');
    $this->db->join('branch b','s.branchID=b.id ','left');
    $query = $this->db->get('super_sales s');
    if($query->num_rows()>0){
        return $query->result_array();
    }else{
        return FALSE;
    }
}
函数getbranchSalesreportshift($limit、$offset、$order\u column、$order\u type、$parameters) { $this->db->select(“str_to_date”(concat(yearweek(s.creationdate),'sunday'),'%X%V%W')作为周,b.name作为分支名称,g.name作为组名,st.name作为班次名称,count(*)作为总销售方,sum(s.price)作为总销售,count(如果salesAdvanceAmount>0,那么s.customerid end)作为总预付方,sum(salesAdvanceAmount>0时的案例,然后salesAdvanceAmount end)作为预付款总额,计数(日期(s.creationdate)日期(customerCreationDate)然后1 end)作为旧的销售方,总和(日期(s.creationdate)日期(customerCreationDate)然后是价格end)作为旧的销售金额,计数(日期(s.creationdate)时的案例)=日期(customerCreationDate)然后1 END)作为新的销售方,sum(如果日期(s.creationdate)=日期(customerCreationDate)然后s.price END)作为新的销售金额,count(returnID)作为退货产品,sum(或价格)作为退货金额); 如果($parameters['shift']!=NULL){ $this->db->like('s.shiftID',$parameters['shift']); } if($parameters['cdatefrom']!=NULL){ //$this->db->where('yearweek(s.creationdate)'、date('YW',strottime($parameters['cdatefrom'])); $this->db->where('str_to_date(concat(yearweek(s.creationdate),“星期二”),%X%V%W”)、date('YW',strotime('parameters['cdatefrom']); } $this->db->group_by(数组(“s.shiftID”、“str_to_date”(concat(yearweek(s.creationdate)”,“星期二”),“%X%V%W”); if(空($order_列)| |空($order_类型)){ $this->db->order_by('yearweek(s.creationdate)','asc'); }否则{ $this->db->order\u by($order\u column,$order\u type); } 如果($limit!=0){ $this->db->limit($limit,$offset); } $uid=$this->session->userdata('id'); $this->db->where('b.ownerid',$uid); $this->db->join('open_返回orn','s.branchhid=orn.branchhid','left'); $this->db->join('shifts st','s.shiftID=st.id','left'); $this->db->join('groupg','s.groupID=g.id','left'); $this->db->join('branch b','s.branchID=b.id','left'); $query=$this->db->get('super_sales'); 如果($query->num\u rows()>0){ 返回$query->result_array(); }否则{ 返回FALSE; } } 这是我的等效原始查询(不能将相等符号放在列和位置附近的值之间)

选择str_to_date(concat(yearweek(s.creationdate),'sunday'),'%X%V%W')作为星期,'b`.'name`作为'branchname`,'g`.'name`作为'groupname`,'st`.'name`作为'shiftname`,count(*)作为总销售额,sum(s.price)作为总销售额,count(salesAdvanceAmount>0时,则s.customerid end)作为总预付款,sum(salesAdvanceAmount>0时的案例,然后salesAdvanceAmount end)作为预付款总额,计数(日期(s.creationdate)日期(customerCreationDate)然后1 end)作为旧的销售方,总和(日期(s.creationdate)日期(customerCreationDate)然后是价格end)作为旧的销售金额,计数(日期(s.creationdate)时的案例)=日期(customerCreationDate)然后1 END)作为新的销售方,sum(如果日期(s.creationdate)=日期(customerCreationDate)然后s.price END)作为新的销售金额,count(returnID)作为退货产品,sum(或价格)作为'super'u sales`s`LEFT JOIN`open`的返回金额,返回'orn`s`.'branchID`='orn`.'branchID`LEFT JOIN`shift`s`.'shiftID`='st`.'id`LEFT JOIN`g`ON`s`.'groupID`='g`.'id`LEFT JOIN`b`s`.'s`.'s`.'s`.'branchID`.'stru去哪里的时间(concat(yearweek(s.creationdate),'s),'X%W)''201842'和'b`.'ownerid`='189'组由's`.'shiftID`,str_至_日期(concat(yearweek(s.creationdate),'sunday'),'%X%V%W')订单由'week'描述限额50
我发现如下所示的原始查询是正确的,但我需要相应过滤器/位置的正确CodeIgniter编码

SELECT str_to_date(concat(yearweek(creationdate), 'sunday'), '%X%V %W') as week,b.name as branchname,g.name as groupname,st.name,count(*) as total_sales_party,sum(price) as total_sales,count(case when salesAdvanceAmount > 0 then customerid end) as total_advance_party,sum(case when salesAdvanceAmount > 0 then salesAdvanceAmount end) as total_advance_amount,count(CASE WHEN DATE(creationdate) <> Date(customerCreationDate) then 1 end ) as old_sales_party,sum(CASE WHEN DATE(creationdate) <> Date(customerCreationDate) THEN price END ) as old_sales_amount,count(CASE WHEN DATE(creationdate) = Date(customerCreationDate) THEN 1 END ) as new_sales_party,sum(CASE WHEN DATE(creationdate) = Date(customerCreationDate) THEN price END ) as new_sales_amount FROM `super_sales` `s` LEFT JOIN branch b ON `s`.branchID=b.id LEFT JOIN `group` g ON `s`.groupID=g.id LEFT JOIN shifts st ON s.shiftID=st.id where str_to_date(concat(yearweek(s.creationdate), 'tuesday'), '%X%V %W') = '2018-10-16' AND b.ownerid=189 GROUP BY str_to_date(concat(yearweek(s.creationdate), 'tuesday'), '%X%V %W'),s.shiftID ORDER BY week DESC 
选择str_to_date(concat(yearweek(creationdate),'sunday'),'%X%V%W')作为周,b.name作为分支名,g.name作为组名,st.name,count(*)作为总销售额,sum(price)作为总销售额,count(当salesAdvanceAmount>0时,则customerid结束)作为总预付款,sum(当salesAdvanceAmount>0时,则salesAdvanceAmount结束)作为预付款总额,将日期(creationdate)日期(customerCreationDate)计算为旧的销售方,将金额(CASE WHEN DATE(creationdate)日期(customerCreationDate)计算为旧的销售方,将日期(creationdate)=日期(customerCreationDate)计算为新的销售方,将金额(CASE WHEN DATE(creationdate))计算为新的销售方=日期(customerCreationDate)然后价格结束)作为新的销售金额,从'super_sales''s'左加入's'上的分支b.branchID=b.id左加入's'上的组g.groupID=g.id左加入转移到s.shiftID=st.id,其中STRU截止日期(concat(yearweek(s.creationdate),'周二'),'X%V%W')='2018-10-16'和b.ownerid=189按STRU截止日期分组(concat(yearweek(s.creationdate)、“周二”)、“%X%V%W”)、s.shiftID按周顺序说明

我需要按星期二、工作日(如select中的“周”列)筛选数据这是一个相当困难的问题,因为您必须了解查询生成器和底层数据库驱动程序的工作方式

问题是,通常Querybuilder会在where条件下为给定的键添加后缀,默认值为
=
。但是在您的情况下,它不会这样做,因为它认为它有一个运算符

这正是我想要的
SELECT str_to_date(concat(yearweek(creationdate), 'sunday'), '%X%V %W') as week,b.name as branchname,g.name as groupname,st.name,count(*) as total_sales_party,sum(price) as total_sales,count(case when salesAdvanceAmount > 0 then customerid end) as total_advance_party,sum(case when salesAdvanceAmount > 0 then salesAdvanceAmount end) as total_advance_amount,count(CASE WHEN DATE(creationdate) <> Date(customerCreationDate) then 1 end ) as old_sales_party,sum(CASE WHEN DATE(creationdate) <> Date(customerCreationDate) THEN price END ) as old_sales_amount,count(CASE WHEN DATE(creationdate) = Date(customerCreationDate) THEN 1 END ) as new_sales_party,sum(CASE WHEN DATE(creationdate) = Date(customerCreationDate) THEN price END ) as new_sales_amount FROM `super_sales` `s` LEFT JOIN branch b ON `s`.branchID=b.id LEFT JOIN `group` g ON `s`.groupID=g.id LEFT JOIN shifts st ON s.shiftID=st.id where str_to_date(concat(yearweek(s.creationdate), 'tuesday'), '%X%V %W') = '2018-10-16' AND b.ownerid=189 GROUP BY str_to_date(concat(yearweek(s.creationdate), 'tuesday'), '%X%V %W'),s.shiftID ORDER BY week DESC 
$this->db->where('str_to_date(concat(yearweek(s.creationdate), "tuesday"), "%X%V %W") =',date('YW',strtotime($parameters['cdatefrom'])));