[英]Select time from base as UNIX_TIMESTAMP(time) laravel 5
I have in base field with type datetime
, it's time
field. 我在类型为
datetime
基本字段中有time
字段。 I want to get all elements from base and get additional timeu
field - it's UNIX_TIMESTAMP(time)
. 我想从base获取所有元素,并获取其他
timeu
字段-它是UNIX_TIMESTAMP(time)
。 I try to do this by add ->select('*','UNIXTIMESTAMP(time) AS timeu')
but Laravel gives me error. 我尝试通过添加
->select('*','UNIXTIMESTAMP(time) AS timeu')
来执行此操作,但是Laravel给了我错误。 I need it to use in ->keyBy()
. 我需要它在
->keyBy()
。 I have next error: 我有下一个错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'UNIX_TIMESTAMP(time)' in 'field list' (SQL: select *, `UNIX_TIMESTAMP(time)` as `timeu` from `values` where UNIX_TIMESTAMP(time) <= 1429135199 and UNIX_TIMESTAMP(time) >= 1428444000 order by `id` asc)
How can I fix it? 我该如何解决?
Laravel needs to know that UNIX_TIMESTAMP(time) as timeu
is a RAW SQL expression and not a column name: Laravel需要知道
UNIX_TIMESTAMP(time) as timeu
是RAW SQL表达式,而不是列名:
->select('*', \DB::raw('UNIX_TIMESTAMP(time) AS timeu'))
Or alternatively: 或者:
->selectRaw('*, UNIX_TIMESTAMP(time) AS timeu')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.