mardi 3 novembre 2015

MySql how to get `END AS` of `CASE` statement with checking another condition by `IF` or another `CASE`

I have the following query what i want to do is controlling the END AS of a SELECT CASE with checking another condition.

set @lang = 'pr';

select 
  COUNT(t1.id) as total, 
  COUNT(t1.id) as 'Total', 
  CASE t2.`precence`
        WHEN '0' THEN 'Absent'
        WHEN '1' THEN 'Present'
        ELSE 'Unknown'
    END AS series,
  CONCAT(DAYNAME(t1.date),' ',DATE_FORMAT(t1.date,'%Y %M %d')) AS ticks,
  CONCAT(DATE_FORMAT(t1.date, '%a'),' ',DATE_FORMAT(t1.date,'%Y %M %d')) AS abv,
    courses.no AS label,
  CASE t2.`precence`
        WHEN '0' THEN IF(@lang = 'en','Absent Participant',IF(@lang = 'pr','غیر حاضر',IF(@lang = 'pa','test','unkown')))
        WHEN '1' THEN IF(@lang = 'en','Present Participant',IF(@lang = 'pr','حاضر',IF(@lang = 'pa','حاضر','unkown')))
        ELSE IF(@lang = 'en','Unknown State',IF(@lang = 'pr','نامعلوم',IF(@lang = 'pa','نامعلوم','unkown')))
    END AS IF(@lang = 'en','Attendance Status',IF(@lang = 'pr','وضعیت حاضری',IF(@lang = 'pa','وضعیت حاضری','Attendance State')))),
    CONCAT(DAYNAME(t1.date),' ',DATE_FORMAT(t1.date,'%Y %M %d')) AS IF(@lang = 'en','Attendance Date',IF(@lang = 'pr','تاریخ حاضری',IF(@lang = 'pa','تاریخ حاضری','Attendance Date'))),
    CONCAT(DATE_FORMAT(t1.date, '%a'),' ',DATE_FORMAT(t1.date,'%Y %M %d')) AS 'Attendance Date (abv)',
    courses.no AS 'Course Number'

FROM course_attendances as t1 left join `student_attendances` as t2 on t2.`course_attendance_id` = t1.`id`
RIGHT JOIN courses ON courses.id = t1.course_id
WHERE t1.`course_id` = '1' AND t1.date BETWEEN '2015-01-01' AND '2016-11-17'
GROUP BY t1.`date`,t2.`precence`

But in END AS section of CASE statement query stop and shows that query is wrong, how can i solve that.

Aucun commentaire:

Enregistrer un commentaire