เขียน query ได้ แต่บันทึกใน view ไม่ได้ ช่วยด้วย ขึ้นว่า You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near SET @sql := ''; SELECT
ทำใน phpmyadmin MySQLAdministrator สร้างไม่ได้อย่างนี้ค่ะ
Code (SQL)
SET @sql := '';
SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'CASE WHEN work_date = ''',
work_date,
''' THEN work_detail else ''-'' END AS `',
work_date, '`'
)
) INTO @sql
FROM persons left join works on persons.person_id = works.person_id
WHERE (WEEKDAY(work_date) BETWEEN 0 AND 4)
AND (WEEK(work_date) = WEEK(now()))
AND (person_active = "Y");
SET @sql = CONCAT('SELECT p.person_name, p.person_position, ', @sql, '
from persons p
inner join works w
on p.person_id = w.work_id
group by p.person_id');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;