我正在尝试在Laravel中运行以下代码 $ posts = DB :: table('rmm')
->select( array('message', DB::raw('COUNT(message) as number'), DB::raw('rmm.receivedTime as time')))
->join( 'rcs', 'rmm.smsCid', '=', 'rcs.smsCid', 'INNER')
->where(DB::raw('rcs.status =1 and rmm.receivedTime > \'2012-12-26\' and rmm.receivedTime LIKE \'2013-04-01\' and length(\'message\') >\'3\' '))
->group_by('message')
->get();
并获得了以下错误代码
SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MySQL服务器版本对应的手册,以便在'附近使用正确的语法?第1行的GROUP BY
message
'
SQL: SELECT `message`, COUNT(message) as number, rmm.receivedTime as time FROM `rmm` INNER JOIN `rcs` ON `rmm`.`smsCid` = `rcs`.`smsCid` WHERE rcs.status =1 and rmm.receivedTime > '2012-12-26' and rmm.receivedTime LIKE '2013-04-01' and length('message') >'3' ? GROUP BY `message`
Bindings: array (
0 => NULL,
)
以某种方式在查询中生成?
;我确定如果我解决了它会起作用吗?
答案 0 :(得分:1)
尝试raw_where()
:
->raw_where("rcs.status = 1 AND rmm.receivedTime > '2012-12-26' AND rmm.receivedTime LIKE '2013-04-01' AND length('message') > 3")