0

我需要一点帮助。我需要这个查询

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 服务器版本相对应的手册,以在第 2 行的 'FROM ( resume_experience) WHERE resume_id= '1' ORDER BY DATEdesc'附近使用正确的语法

SELECT *, STR_TO_DATE(end_date, `%d/%m/%Y)` AS DATE FROM (`resume_experience`) WHERE `resume_id` = '1' ORDER BY `DATE` desc

任何帮助将不胜感激。

感谢和等待,

艾哈迈德

4

2 回答 2

0

STR_TO_DATE()需要在格式字符串周围加上引号:

$this->db->select('*,STR_TO_DATE(end_date,"%d/%m/%Y") AS DATE')
于 2014-03-18T14:25:12.597 回答
0

您需要像中一样传递第二个参数FALSEselect()这样它就不会引用STR_TO_DATE(end_date,%d/%m/%Y) AS DATE

$this->db->select("*,STR_TO_DATE(end_date,'%d/%m/%Y') AS DATE",FALSE)

查看活动记录

于 2014-03-18T14:25:13.667 回答