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
-3
A
回答
0
嘗試這樣的,這是更好地查詢
$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
')
+0
您的查詢生成錯誤。 – 2015-03-03 07:18:28
+0
使用雙引號 - (「-query-」) – 2015-03-03 07:27:14
+0
首先檢查您的查詢,然後放入$ this-> db-> query('/ * Inside your query * /'); – 2015-03-03 07:31:04
相關問題
- 1. 如何編寫MySQL查詢像笨
- 2. 轉換模型笨到MySQL查詢
- 3. MySQL查詢在笨
- 4. 笨MySQL查詢
- 5. 如何寫下面的查詢在LINQ
- 6. MySQL查詢笨查詢
- 7. 如何編寫休眠條件查詢下面的SQL查詢
- 8. 全球MySQL查詢在笨
- 9. PHP MySQL查詢在笨
- 10. MySQL查詢在笨3
- 11. 插入MySQL查詢在笨
- 12. 轉換MySQL查詢在笨查詢
- 13. 如何編寫以下mySQL查詢?
- 14. 如何編寫下面的mongo查詢?
- 15. 如何編寫下面的SQL查詢?
- 16. 如何在Yii2中編寫下面的mongo查詢查詢
- 17. 如何撰寫CakePHP的模型查詢
- 18. 分頁的笨2.1.0與模型查詢
- 19. 笨模型功能和/或查詢
- 20. 如何重寫MySQL查詢
- 21. 如何編寫MySQL查詢
- 22. 如何編寫MySQL查詢
- 23. 如何編寫mysql查詢?
- 24. 轉換MySQL查詢到笨
- 25. 笨MySQL查詢陣列
- 26. MySQL查詢問題,笨
- 27. 笨MySQL查詢不工作
- 28. 將MYSQL查詢寫入CSV文件無法寫入查詢
- 29. 笨 - 在查詢條件
- 30. 在笨查詢
爲什麼我們做你的家庭作業?你看看CI的成長嗎?你有嘗試過什麼嗎? – 2015-03-03 07:14:36
[這是文檔](https://ellislab.com/codeIgniter/user-guide/database/active_record.html) – 2015-03-03 07:15:24