Đây là câu hỏi của tôi trong CodeIgniterCodeIgniter: Lỗi trong ORDER BY truy vấn TRƯỜNG HỢP
$this->db->select('p.*,u.firstname, u.lastname,s.title AS industry, pt.type_name , al.length_value',FALSE);
$this->db->from($this->_tbl_projects . ' as p');
$this->db->join($this->_tbl_client_details . ' as c', 'c.id = p.client_id', 'left');
$this->db->join($this->_tbl_users . ' as u', 'u.id = c.user_id', 'left');
$this->db->join($this->_tbl_project_types . ' as pt', 'pt.project_type_id = p.project_type_id', 'left');
$this->db->join($this->_tbl_specializations . ' as s', 's.specialization_id = p.specialization_id', 'left');
$this->db->join($this->_tbl_article_length . ' as al', 'al.article_length_id = p.article_length_id', 'left');
$this->db->order_by("CASE p.submit_to
WHEN '' THEN 0
WHEN 'writer' THEN 1
ELSE 2
END, p.request_end_date asc",FALSE);
Nó In
SELECT p.*, u.firstname, u.lastname, s.title AS industry, pt.type_name, al.length_value
FROM (`projects` as p)
LEFT JOIN `client_details` as c ON `c`.`id` = `p`.`client_id`
LEFT JOIN `users` as u ON `u`.`id` = `c`.`user_id`
LEFT JOIN `project_types` as pt ON `pt`.`project_type_id` = `p`.`project_type_id`
LEFT JOIN `specializations` as s ON `s`.`specialization_id` = `p`.`specialization_id`
LEFT JOIN `article_length` as al ON `al`.`article_length_id` = `p`.`article_length_id` WHERE `p`.`client_id` = '26' AND `p`.`status` IN (2, 3)
ORDER BY
`CASE` p.submit_to
WHEN '' THEN 0
WHEN 'writer' THEN 1
ELSE 2
END, `p`.`request_end_date` asc
đây trong truy vấn in, TRƯỜNG HỢP được in bởi 'TRƯỜNG HỢP `, vì vậy sql ném lỗi.
Tôi có thể giải quyết nó bằng cách nào?
Cấu trúc của lĩnh vực submit_to là
submit_to enum('','writer','students') NOT NULL
Cảm ơn bạn đã trả lời. Cập nhật của bạn hoạt động nhưng không cho kết quả theo thứ tự đúng. Tôi muốn dữ liệu để submit_to = '' sau đó submit_to = 'sinh viên' và cuối cùng submit_to = 'nhà văn'. Nội dung cập nhật của bạn cho kết quả theo thứ tự này 1. '' 2. 'writer' 3. 'students'. – Napster
Đã cập nhật để khớp với đơn đặt hàng đã được sắp xếp lại của bạn. – Thomas