[英]Select time from base as UNIX_TIMESTAMP(time) laravel 5
我在類型為datetime
基本字段中有time
字段。 我想從base獲取所有元素,並獲取其他timeu
字段-它是UNIX_TIMESTAMP(time)
。 我嘗試通過添加->select('*','UNIXTIMESTAMP(time) AS timeu')
來執行此操作,但是Laravel給了我錯誤。 我需要它在->keyBy()
。 我有下一個錯誤:
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)
我該如何解決?
Laravel需要知道UNIX_TIMESTAMP(time) as timeu
是RAW SQL表達式,而不是列名:
->select('*', \DB::raw('UNIX_TIMESTAMP(time) AS timeu'))
或者:
->selectRaw('*, UNIX_TIMESTAMP(time) AS timeu')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.