我需要一些帮助。我需要这个查询
SELECT *, STR_TO_DATE( end_date, "%d/%m/%Y" ) AS DATE
FROM `resume_experience`
WHERE `resume_id` =1
ORDER BY DATE DESC
以codeigniter活动记录格式编写。这就是我写的。
$result = $this->db->select('*,STR_TO_DATE(end_date,%d/%m/%Y) AS DATE')
->from('resume_experience')
->order_by('DATE', "desc")
->where($where)
->get()
->result_array();
return $result;
它给了我以下错误。
您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在#{; FROM(resume_experience
)附近使用正确的语法WHERE resume_id
=' 1' ORDER BY DATE
desc'在第2行
SELECT *, STR_TO_DATE(end_date, `%d/%m/%Y)` AS DATE FROM (`resume_experience`) WHERE `resume_id` = '1' ORDER BY `DATE` desc
非常感谢任何帮助。
谢谢和等待,
艾哈迈德
答案 0 :(得分:0)
STR_TO_DATE()
需要围绕格式字符串的引号:
$this->db->select('*,STR_TO_DATE(end_date,"%d/%m/%Y") AS DATE')
答案 1 :(得分:0)
您需要在FALSE
中将第二个参数作为select()
传递,因此它不会引用STR_TO_DATE(end_date,%d/%m/%Y) AS DATE
$this->db->select("*,STR_TO_DATE(end_date,'%d/%m/%Y') AS DATE",FALSE)