Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在codeigniter模型文件中编写以下mysql查询_Codeigniter - Fatal编程技术网

如何在codeigniter模型文件中编写以下mysql查询

如何在codeigniter模型文件中编写以下mysql查询,codeigniter,Codeigniter,尝试这样做,这对您的查询更好 Select SUM(getWorkingday(Dates.DateFrom,Dates.DateTo,'work_days')) as UnpaidLeave from (Select convert( case when ( YEAR(`DateFrom`)=paramyear and YEAR(`DateTo`)=paramyear and Month(`DateFrom`)<paramonth and Month(`DateTo`)= paramo

尝试这样做,这对您的查询更好

Select SUM(getWorkingday(Dates.DateFrom,Dates.DateTo,'work_days')) as UnpaidLeave 
from (Select convert( case when ( YEAR(`DateFrom`)=paramyear and YEAR(`DateTo`)=paramyear and Month(`DateFrom`)<paramonth and Month(`DateTo`)= paramonth ) then STR_TO_DATE(concat(Year(`DateFrom`),'-',Month(`DateFrom`)+1,'-','01') ,'%Y-%m-%d') Else `DateFrom` end , date) as DateFrom
        , convert( case when ( YEAR(`DateFrom`)=paramyear and YEAR(`DateTo`)=paramyear and Month(`DateFrom`)= paramonth and Month(`DateTo`)>paramonth ) then STR_TO_DATE(concat(Year(`DateTo`),'-',Month(`DateTo`)-1,'-',DAY(LAST_DAY(`DateFrom`))) ,'%Y-%m-%d') Else `DateTo` end , date) as DateTo
    from leaveenjoyed where `EmpId`=paramempid and `LeaveTypeId` in (-1) and (Year(`DateFrom`)= paramyear or Year(`DateTo`)= paramyear) AND (Month(`DateFrom`)= paramonth or Month(`DateTo`)= paramonth)) as Dates

我们为什么做你的家庭作业?你看过词的双重含义吗?您尝试过什么吗?使用双引号--query首先检查您的查询,然后在您的查询中放入$this->db->query'/*;
$this->db->query('Select SUM(getWorkingday(Dates.DateFrom,Dates.DateTo,'work_days')) as UnpaidLeave
from (Select convert( case when ( YEAR(DateFrom)=paramyear and YEAR(DateTo)=paramyear and Month(DateFrom)paramonth ) then STR_TO_DATE(concat(Year(DateTo),'-',Month(DateTo)-1,'-',DAY(LAST_DAY(DateFrom))) ,'%Y-%m-%d') Else DateTo end , date) as DateTo from leaveenjoyed where EmpId=paramempid and LeaveTypeId in (-1) and (Year(DateFrom)= paramyear or Year(DateTo)= paramyear) AND (Month(DateFrom)= paramonth or Month(DateTo)= paramonth)) as Dates
')