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. 如何寫下面的查詢在LINQ
- 5. MySQL查詢笨查詢
- 6. 如何編寫休眠條件查詢下面的SQL查詢
- 7. 插入MySQL查詢在笨
- 8. PHP MySQL查詢在笨
- 9. 如何編寫以下mySQL查詢?
- 10. 如何在Yii2中編寫下面的mongo查詢查詢
- 11. 如何編寫下面的mongo查詢?
- 12. 如何編寫下面的SQL查詢?
- 13. 如何在這種類型的條件下編寫SQL查詢
- 14. 笨MySQL查詢陣列
- 15. MySQL查詢問題,笨
- 16. 笨MySQL查詢不工作
- 17. 轉換MySQL查詢到笨
- 18. 如何編寫MySQL查詢
- 19. 如何編寫mysql查詢?
- 20. 笨 - 在查詢條件
- 21. 查詢在笨
- 22. 如何在MySQL中編寫此查詢?
- 23. 如何在PHP中縮寫MySQL查詢?
- 24. 如何在MySQL中編寫此查詢?
- 25. 笨 - 如果模型的MySQL查詢失敗,送flashdata回給用戶
- 26. 我如何寫查詢來獲取以下輸出在MySQL
- 27. 查詢在phpMyAdmin運行而不是在笨模型
- 28. 致命錯誤:在寫上下文笨
- 29. 查詢在SQL笨
- 30. 如何寫C#查詢到JSON文件
爲什麼我們做你的家庭作業?你看看CI的成長嗎?你有嘗試過什麼嗎? – 2015-03-03 07:14:36
[這是文檔](https://ellislab.com/codeIgniter/user-guide/database/active_record.html) – 2015-03-03 07:15:24