2021年1月7日星期四

SQLSTATE[42703]: Undefined column: 7 ERROR: column "1" does not exist LINE 1:

I'm trying to convert SQL into Laravel query builder. When I run my coding, I got this error.

Error

Here my SQL coding:

    SELECT date_trunc('day', created_at) AS hour_stamp,        (extract(hour FROM created_at)::int / 60) AS min_slot,        count(*),        max(e4) as kwh  FROM energydata_1001  WHERE api_key_value= 'YaB8JCcE'  AND date(created_at) >= '2020-11-30 23:59:59'  AND date(created_at) <= '2020-12-29 00:00:00'  GROUP  BY 1, 2  ORDER  BY 1, 2;  

And here my laravel query builder:

$rnd = DB::table('energydata_1001')->select(DB::raw('DATE_TRUNC(\'day\', created_at) AS hour_stamp'));    /* select statements */          $rnd = $rnd->addSelect(DB::raw('(EXTRACT(hour FROM created_at)::int / 60) AS min_slot'));          $rnd = $rnd->addSelect(DB::raw('COUNT(*)'));          $rnd = $rnd->addSelect(DB::raw('MAX(e4) AS kwh'));    /* where clause */          $rnd = $rnd->where('api_key_value', 'YaB8JCcE');          $rnd = $rnd->where('created_at', '>=', '2020-11-30 23:59:59');          $rnd = $rnd->where('created_at', '<=', '2020-12-29 00:00:00');            $rnd = $rnd->groupBy(1,2);          $rnd = $rnd->orderBy(1);          $rnd = $rnd->orderBy(2);          $rnd = $rnd->get();            // dd($rnd);          return view('R&D.index',compact('rnd'));  

I hope someone can help me to solve this problem. I already read the Laravel Documentation, but I couldn't find any way to solve my problem. Thanks in advance.

https://stackoverflow.com/questions/65622474/sqlstate42703-undefined-column-7-error-column-1-does-not-exist-line-1 January 08, 2021 at 10:06AM

没有评论:

发表评论